www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8324] New: Arrays seen as callables for map/filter

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8324

           Summary: Arrays seen as callables for map/filter
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8324


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch



Also see issue 6110.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2012