Bug 6110 – std.functional: unaryFun should take an array alias.
Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-06-05T15:55:36Z
Last change time
2017-08-28T08:51:09Z
Assigned to
No Owner
Creator
timon.gehr
Comments
Comment #0 by timon.gehr — 2011-06-05T15:55:36Z
I find myself writing code similar to the following quite a lot:
auto bbb = new bool[MAX];
auto arr = new int[MAX];
//...
writeln(filter!((a){return bbb[a];})(arr));
I think that it should be possible to do
writeln(filter!bbb(arr));
for the same effect.
It is generally useful to use an array as a function that maps integral indexes to the element type of the array.
Therefore, I propose to improve unaryFun so that it implements the proposed semantics.
Comment #1 by peter.alexander.au — 2014-02-02T10:24:21Z
I think this was before lambdas. Do you still think this is necessary now that you can write:
filter!(a => bbb[a])
???
Comment #2 by bearophile_hugs — 2014-02-02T10:49:08Z
(In reply to comment #1)
> I think this was before lambdas. Do you still think this is necessary now that
> you can write:
>
> filter!(a => bbb[a])
>
> ???
I think the enhancement request by Timon is still a nice thing to ask. Using arrays and associative arrays as functions for the higher order functions is handy, and it's done often in the Clojure language.
Comment #3 by andrei — 2016-10-14T15:37:05Z
This looks irregular so I'll close it. Feel free to reopen if more motivation is available.
Comment #4 by razvan.nitu1305 — 2017-08-28T08:51:09Z
*** Issue 8324 has been marked as a duplicate of this issue. ***