std.algorithm.map with side-effects

evenex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Dec 5 16:16:52 PST 2014


map won't actually compute anything until you start asking for
individual elements with front, back, or opIndex.

Personally I like to use something like

   ref transform (alias action, R, T...)(ref R range, T addl_args)
     {
       range = action (range, addl_args);
       return range;
     }

to do mutation in the middle of UFCS chains. Its more flexible
and more obvious than an impure map.

     range.callchain.array.transform!(x => 
x.map!whatever).filter.etc


More information about the Digitalmars-d-learn mailing list