[Issue 8715] map, filter, zip with functional arrays/associative arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Dec 13 02:55:07 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8715
bearophile_hugs at eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|zipWith |map, filter, zip with
| |functional
| |arrays/associative arrays
--- Comment #5 from bearophile_hugs at eml.cc 2012-12-13 02:53:58 PST ---
Another example:
import std.stdio: writeln;
import std.algorithm: map, filter;
void main() {
int[] data = [0, 1, 2, 3];
bool[] mask = [true, false, true, false];
int[int] conv = [0:10, 1:20, 2:30, 3:40];
auto r1 = data
.filter!(i => mask[i])()
.map!(i => conv[i])();
writeln(r1); // Prints: [10, 30]
}
This is nicer:
import std.stdio: writeln;
import std.algorithm: map, filter;
void main() {
int[] data = [0, 1, 2, 3];
bool[] mask = [true, false, true, false];
int[int] conv = [0:10, 1:20, 2:30, 3:40];
auto r2 = data.filter!mask().map!conv();
writeln(r2);
}
--
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