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

crimaniak via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 23 15:00:42 PDT 2016


On Monday, 21 March 2016 at 11:48:52 UTC, Seb wrote:
> On Monday, 21 March 2016 at 11:35:49 UTC, Timothee Cour wrote:
>> assert(9.iota.emit!(int,(put,a){if(a%2) put(a*a);}).equal([1, 
>> 9, 25, 49]))
I support idea to have such feature, sometimes it really need.

>
> Could you try to point out whats wrong with map & filter?
>
> assert(9.iota.filter!"a%2".map!"a*a".equal([1, 9, 25, 49])

map: 1 element -> 1 element
filter: 1 element -> 0..1 element(s)

emit: 1 element -> 0..infinite elements

This feature is more generic then map() and filter() together. 
But proposed implementation is not good. I think this is good 
place for generator function with yield.
If map() will accept generators and process it as expected, 
different from ordinary functions, then additional emit() method 
is not needed. And filter() too :)



More information about the Digitalmars-d mailing list