Should reduce take range as first argument?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon May 14 14:33:24 PDT 2012
On 5/14/12 4:10 PM, Justin Whear wrote:
> 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
Yah, reduce was not designed for the future benefit of UFCS. (I recall
take() was redefined towards that vision, and it was a good move.)
We can actually deprecate the current order and accept both by inserting
the appropriate template constraints. We change the documentation and
examples to reflect the new order, and we leave a note saying that the
old order is deprecated. We can leave the deprecated version in place
for a long time. Thoughts?
Andrei
More information about the Digitalmars-d
mailing list