Function called twice

Adam D. Ruppe destructionator at gmail.com
Fri Aug 2 22:35:53 UTC 2019


On Friday, 2 August 2019 at 21:44:28 UTC, Jordan Wilson wrote:
> 	// outputs 1 2 2 3
> 	z.map!(a => tuple!("number","iseven")(a, a.isEven))
> 	 .filter!(a => a.iseven)
> 	 .array;

I *think* what's happening here is first it calls map() first 
going into the filter... then it gets called again when it is 
being evaluated for the array.

So like basically consider if you had:

if(filter(a())
    array ~= a();


that kind of thing. I think anyway, I'm not entirely sure but it 
fits what I can see happening here.

but idk why it is actually doing this in the phobos implementation


More information about the Digitalmars-d-learn mailing list