Should reduce take range as first argument?

Justin Whear justin at economicmodeling.com
Mon May 14 14:10:28 PDT 2012


In its current form, std.algorithm.reduce takes optional seed value(s) 
for the accumulator(s) as its first argument(s). This breaks the nice 
chaining effect made possible by UFCS:

Works:
-----------------------------------------
auto foo = reduce!((string s, string x) => s ~= x)("BLAH", args.map!(x => 
x[1..$-1]));
-----------------------------------------

Doesn't work, but looks much nicer:
-----------------------------------------
auto foo = args.map!(x => x[1..$-1]))
               .reduce!((string s, string x) => s ~= x)("BLAH");
-----------------------------------------

This could be fixed with a breaking change by making the subject range to 
be the first parameter. Aside from breaking existing code, are there 
other obstacles to changing this?

Justin Whear


More information about the Digitalmars-d mailing list