std.algorithm.map with side-effects
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Dec 5 15:58:47 PST 2014
Joseph Rushton Wakeling:
> Can anyone advise why,
map is lazy, like most other ranges.
> and whether there's a nice range iteration option to ensure
> that this function gets called using each element of the
> filteredRange?
Lazy higher order functions like map/filter should be used only
with pure functions. There are bugs/troubles in using them on
impure code.
There was a proposal for a "each" function to terminate a range
chain with something effectful, but I think it has gone nowhere.
This means you have to use a foreach on a range.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list