Bug 5075 – std.algorithm.map/filter don't support associative arrays

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-10-18T19:04:00Z
Last change time
2013-03-30T13:56:11Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-10-18T19:04:16Z
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()); }
Comment #1 by kennytm — 2010-10-18T23:37:04Z
See issue 4067.
Comment #2 by kennytm — 2010-10-18T23:37:42Z
(In reply to comment #1) > See issue 4067. I mean issue 4607 :|.
Comment #3 by bearophile_hugs — 2010-10-19T13:42:36Z
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.
Comment #4 by bearophile_hugs — 2012-01-17T14:15:01Z
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.
Comment #5 by bearophile_hugs — 2013-03-30T13:56:11Z
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.