www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't chain reduce(seed, range)

reply "Yuxuan Shui" <yshuiv7 gmail.com> writes:
Why is reduce defined as 'auto reduce(S, R)(S seed, R r)', 
instead of reduce(R r, S seed)? I can't chain it.

Maybe provide both?
Aug 30 2015
next sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Monday, August 31, 2015 01:31:58 Yuxuan Shui via Digitalmars-d-learn wrote:
 Why is reduce defined as 'auto reduce(S, R)(S seed, R r)',
 instead of reduce(R r, S seed)? I can't chain it.

 Maybe provide both?
The reasons why the seed is first are historical. It predates UFCS being added to the language, so there was no reason to put the range first when when it was added to Phobos. I believe that there have been attempts to fix it, but AFAIK, they ran into too many problems to be able to do it without breaking existing code. - Jonathan M Davis
Aug 30 2015
prev sibling parent "rsw0x" <anonymous anonymous.com> writes:
On Monday, 31 August 2015 at 01:32:01 UTC, Yuxuan Shui wrote:
 Why is reduce defined as 'auto reduce(S, R)(S seed, R r)', 
 instead of reduce(R r, S seed)? I can't chain it.

 Maybe provide both?
You might be interested in this PR https://github.com/D-Programming-Language/phobos/pull/1955 It's a bit old, left a ping to see what's up.
Aug 31 2015