Bug 11128 – std.algorithm.reduce one-argument version cannot always be chained using UFCS
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-26T22:53:00Z
Last change time
2015-06-09T05:15:19Z
Assigned to
nobody
Creator
daniel350
Comments
Comment #0 by daniel350 — 2013-09-26T22:53:16Z
Example:
arr1.reduce!((s, x) => s + (x / 3));
Because the natural seed value is arr1.front, depending on the type, this will return an incorrect result, so you therefore need to provide a seed, using the one-argument version of std.algorithm.reduce, this cannot be done.
You are therefore forced to use the standard syntax:
reduce!((s, x) => s + (x / 3))(0, arr1);
Or:
0.reduce!((s, x) => s + (x / 3))(arr1);
This seems counter-intuitive, compared to:
arr1.reduce!((s, x) => s + (x / 3))(0);
This change wouldn't play pretty.
Comment #1 by peter.alexander.au — 2013-09-27T14:43:37Z
Yep, it's irritating, and a known issue. Closing as dupe.
*** This issue has been marked as a duplicate of issue 8755 ***