Bug 8324 – Arrays seen as callables for map/filter
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-30T07:28:23Z
Last change time
2017-08-28T08:51:08Z
Assigned to
No Owner
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-06-30T07:28:23Z
A low-priority enhancement request.
In some cases the mapping function is just an array or associative array:
import std.stdio, std.range, std.algorithm;
void main() {
auto a = [0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1];
iota(0, a.length).filter!(i => a[i])().writeln();
}
Output:
[1, 4, 9, 16]
So maybe filter/map (and few other higher order functions) can be improved (using a new little function in std.functional) to see a given array/associative array as a callable:
iota(0, a.length).filter!a().writeln();
The Clojure language supports something similar.
Comment #1 by timon.gehr — 2012-06-30T07:39:39Z
Also see issue 6110.
Comment #2 by razvan.nitu1305 — 2017-08-28T08:51:08Z
*** This issue has been marked as a duplicate of issue 6110 ***