emit: generalizes map, filter, joiner [proposal + implementation]

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 21 04:35:49 PDT 2016


given fun(put, a) a lambda that can call $put 0 or more times,
some_range.emit!fun computes a range formed of all the calls to $put

eg:
assert(9.iota.emit!(int,(put,a){if(a%2) put(a*a);}).equal([1, 9, 25, 49]));

in this case it can be done by combining map and filter but in other cases
emit is more powerful and an equivalent (with map,filter,joiner) can be
inefficient and more complex.

see https://github.com/timotheecour/dtools/blob/master/dtools/util/emit.d

could that be turned into std.algorithm.iteration.emit (after addressing
comments) ?

Any comments would be appreciated (especially regarding whether we can get
rid of the 1st template argument with type deduction)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160321/a02d5e6b/attachment.html>


More information about the Digitalmars-d mailing list