Intrinsics, std.bind problems, list comphrensions, recursivity test
Henning Hasemann
hhasemann at web.de
Fri Aug 24 02:54:05 PDT 2007
This is untested:
/**
* Resembles pythons list comprehensions
* Read as
* returns *apply* applied to each *iter* in *collection* where *where*
*
* for example:
*
* int i;
* select(toString(i), i, [1,2,3,4,5,6,7], i % 2 == 0)
*
* would return:
* ["2", "4", "6"]
*/
R[] select(R, I, C)(lazy R apply, ref I iter, C collection, lazy bool
where) { R[] r;
foreach(x; collection) {
iter = x;
if(where())
r ~= apply();
}
return r;
}
--
GPG Public Key:
http://keyserver.ganneff.de:11371/pks/lookup?op=get&search=0xDDD6D36D41911851
Fingerprint: 344F 4072 F038 BB9E B35D E6AB DDD6 D36D 4191 1851
More information about the Digitalmars-d-learn
mailing list