D templates + IFTI + Tuples + delegate literals = holy bovine!
Vassily Gavrilyak
gavrilyak at gmail.com
Mon Feb 26 12:21:12 PST 2007
Cool stuff, almost what I searched for. filter works like a charm.
However not so for map and reduce. The return type of map and reduce is different
from the type of item in collection.
I'm just started to look at D, so don't know the right way to write those functions.
Declaration in Nemerle looks like this
public Map['a, 'b] (l : list ['a], f : 'a -> 'b) : list ['b] {
$[ f(x) | x in l ]
}
So we have 2 types here, type of collection and type of result
And reduce(fold) has 2 types too.
So basically the following code:
struct Person{ int id; char[] name;}
static Person[] people= [{1, "Joe"}, {2, "Bill"}];
int[] ids = map(persons, delegate int(Person p){return p.id;});
should produce [1,2]
Is that possible in D?
More information about the Digitalmars-d
mailing list