Map, filter and pure functions

Paul Backus snarwin at gmail.com
Fri Nov 29 16:07:37 UTC 2019


On Friday, 29 November 2019 at 15:54:13 UTC, realhet wrote:
> On Friday, 29 November 2019 at 15:49:24 UTC, Paul Backus wrote:
>> It's actually a much simpler reason: filter calls .front twice 
>> for each element in its input (once to check if the value 
>> satisfies the predicate, and then again to return the value if 
>> it does), and the range returned by map doesn't save the value 
>> of .front between calls, so it has to re-compute it each time 
>> by calling the transform function.
>
> This makes it clear.
>
> In my case a cache which can access all the previous elements 
> would be a too big thing, so I will do the filtering in a later 
> stage manually. But most importantly, now I know what's going 
> on, Thank You!

The "cache" wrapper only caches one element at a time. The cached 
value is discarded after each call to .popFront.


More information about the Digitalmars-d-learn mailing list