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

thedeemon via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 23 20:21:30 PDT 2016


On Monday, 21 March 2016 at 23:09:27 UTC, Tamas wrote:
> On Monday, 21 March 2016 at 11:48:52 UTC, Seb wrote:
>> Could you try to point out whats wrong with map & filter?
> It's hard to do stuff like this:
>
> assert(9.iota.emit!(int,(put,a){if(a%2) put(a*a); if(a%3==0) 
> put(a);}).equal([1,9,3,25,6,49]));

Is it a bug or you forgot 0 here?

How it looks with Phobos today:

     auto r = new Generator!int({
         9.iota.each!((a) { if (a % 2) yield(a*a); if (a % 3 == 0) 
yield(a); });
     });
     assert(r.equal([0,1,9,3,25,6,49]));

Probably much less efficient, of course.


More information about the Digitalmars-d mailing list