D-Programming-Language/phobos — pull request #2033 by monarchdodra (2014-03-20 19:30:15+00:00)
Title: introduce "fold" to std.algorithm

Try 2.

This time, I think the pull is complete, so fire away and destroy anything you like. Should I apply for "formal review"? I'll post about this on the boards after the initial salvo here ;)

--------

`fold` is basically still the same thing as reduce, but "fixes" some interface issues that were not fixable without breakage. Namelly, palcing the range before the seed, for UFCS friendliness. Not a huge problem, but a common enough occurrence to cause frustration, and justify fixing.

Furthermore, it also improves usability by making the seeds passed by parameter pack, instead of forcing the use of a `tuple`.

Finally, it allows using only 1 seed, in which case, the same seed is replicated and is used for all the functions.

Oh yeah, also, I made it so that when no seed is given, it is an `Error` to use an empty range. This is the *only* case of deviation, but I think having nothrow justifies it.

"iterables" are not supported anymore.

These changes should make for an overall nicer D experience, and justify the update via a new name. Old code should not be impacted.

--------

Implementation wise, I think `fold` is very neat, and contains lots of improvements over `reduce`: Shorter code, better initialization scheme, a better inference mechanism for guessing the seed type...

But it doesn't actually contain anything I couldn't port back to reduce afterwards. Most of it anyways I think.