[Issue 5075] New: std.algorithm.map/filter don't support associative arrays or their byKey()/byValue()
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 18 19:04:53 PDT 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 at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at 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: -------
More information about the Digitalmars-d-bugs
mailing list