Thread overview
[Issue 5075] New: std.algorithm.map/filter don't support associative arrays or their byKey()/byValue()
Oct 19, 2010
kennytm@gmail.com
Oct 19, 2010
kennytm@gmail.com
[Issue 5075] std.algorithm.map/filter don't support associative arrays
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5075

           Summary: std.algorithm.map/filter don't support associative
                    arrays or their byKey()/byValue()
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: bearophile_hugs@eml.cc


--- Comment #0 from bearophile_hugs@eml.cc 2010-10-18 19:04:16 PDT ---
This is a small interactive REPL with Python 2.6:


>>> data = {1:4, 2:3, 3:1, 4:0}
>>> map(lambda x: -x, data)
[-1, -2, -3, -4]
>>> filter(lambda x: x > 2, data)
[3, 4]
>>> # works with lazy map and lazy filter too:
>>> from itertools import imap, ifilter
>>> list(imap(lambda x: -x, data))
[-1, -2, -3, -4]
>>> list(ifilter(lambda x: x > 2, data))
[3, 4]


'data' is an associative array, and "lambda" is used to define local anonymous functions.

But map and filter in current Phobos with DMD 2.049 don't seem to support associative arrays as inputs:


import std.algorithm: map, filter;
void main() {
    int[int] data = [1:4, 2:3, 3:1, 4:0];
    auto r1 = map!((int x) { return -x; })(data);
    auto r2 = filter!((int x) { return x > 2; })(data);
}


Nor byKey()/byValue():

import std.algorithm: map, filter;
void main() {
    int[int] data = [1:4, 2:3, 3:1, 4:0];
    auto r1 = map!((int x) { return -x; })(data.byKey());
    auto r2 = filter!((int x) { return x > 2; })(data.byKey());
    auto r3 = map!((int x) { return -x; })(data.byValue());
    auto r4 = filter!((int x) { return x > 2; })(data.byValue());
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5075


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm@gmail.com


--- Comment #1 from kennytm@gmail.com 2010-10-18 23:37:04 PDT ---
See issue 4067.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5075



--- Comment #2 from kennytm@gmail.com 2010-10-18 23:37:42 PDT ---
(In reply to comment #1)
> See issue 4067.

I mean issue 4607 :|.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5075


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 19, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5075



--- Comment #3 from bearophile_hugs@eml.cc 2010-10-19 13:42:36 PDT ---
So the second part of this bug report (about byKey()/byValue()) is a dupe. The
first part is an enhancement request that I think is not duplicated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 17, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5075


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|std.algorithm.map/filter    |std.algorithm.map/filter
                   |don't support associative   |don't support associative
                   |arrays or their             |arrays
                   |byKey()/byValue()           |


--- Comment #4 from bearophile_hugs@eml.cc 2012-01-17 14:15:01 PST ---
After fixing issue 4607 this doesn't work still:


import std.algorithm: map, filter;
void main() {
    int[int] data = [1:4, 2:3, 3:1, 4:0];
    auto r1 = map!(x => -x)(data);
    auto r2 = filter!(x => x > 2)(data);
}


Also restricted the name of this issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 07, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5075


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=5075


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX


--- Comment #5 from bearophile_hugs@eml.cc 2013-03-30 13:56:11 PDT ---
Given the current design of Phobos, I think this enhancement request will not be fulfilled. A future associativeArray.byPair that yields 2-tuples is a better solution. So I close this down.

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