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

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 24 05:08:41 PDT 2016


On Wednesday, 23 March 2016 at 17:43:07 UTC, Tamas wrote:
> On Wednesday, 23 March 2016 at 17:29:55 UTC, Nick Treleaven 
> wrote:
>> 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]));
>>
>> Seems doable:
>> mapFilter!((a){if(a%2) return some(a*a); if(a%3==0) return 
>> some(a); return none;})
>
> This one emits only 1 element when a==3.

Oops, thanks.

> (BTW what is `mapFilter` and `some`?)

It combines both functions, the lambda returns an Option type 
representing 0 or 1 element:
http://forum.dlang.org/post/ncom7m$1ebr$1@digitalmars.com




More information about the Digitalmars-d mailing list