[Issue 8755] Change the order of reduce arguments
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 21 01:45:07 PDT 2014
https://d.puremagic.com/issues/show_bug.cgi?id=8755
--- Comment #16 from monarchdodra at gmail.com 2014-03-21 01:44:56 PDT ---
(In reply to comment #15)
> Why is reduce (sorry, fold) allowing multiple function arguments in the first
> place?
>
> If you want to compose functions to avoid another O(n) iteration, then you
> should compose the reduce function to return a tuple yourself.
>
> That way it is clear what the code is doing, instead of this magic N-tuple
> special case return type.
You shouldn't have to need to look at what the code is doing. It's a library.
We accept multiple function arguments because:
auto minmax = myRange.reduce!(min, max)();
Is incredibly straight forward and convenient.
That said, the design doesn't actually prevent you from doing it as you are
asking for:
//-----
auto first = tuple(myRange.front, myRange.front);
myRange.popFront();
auto minmax = reduce!((a, b) => tuple(min(a[0], b), max(a[1], b)))(first,
myRange);
writeln(minmax);
//----
It works, but you'll have a tough time selling it to me.
The only argument in favor of this approach, is if you need the return type to
be different from the tuple type. But as I said, both approaches can co-exist,
so why hold out?
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list