std.algorithm.iteration.reduce.reduce
- multiple declarations
Function reduce.reduce
No-seed version. The first element of r
is used as the seed's value.
auto auto reduce(R)
(
R r
)
if (isIterable!R);
For each function f
in fun
, the corresponding
seed type S
is Unqual!(typeof(f(e, e)))
, where e
is an
element of r
: ElementType!R
for ranges,
and ForeachType!R
otherwise.
Once S has been determined, then S s = e;
and s = f(s, e);
must both be legal.
Parameters
Name | Description |
---|---|
r | an iterable value as defined by isIterable |
Returns
the final result of the accumulator applied to the iterable
Throws
Exception
if r
is empty
Function reduce.reduce
Seed version. The seed should be a single value if fun
is a
single function. If fun
is multiple functions, then seed
should be a Tuple
, with one field per function in f
.
auto auto reduce(S, R)
(
S seed,
R r
)
if (isIterable!R);
For convenience, if the seed is const, or has qualified fields, then
reduce
will operate on an unqualified copy. If this happens
then the returned type will not perfectly match S
.
Use fold
instead of reduce
to use the seed version in a UFCS chain.
Parameters
Name | Description |
---|---|
seed | the initial value of the accumulator |
r | an iterable value as defined by isIterable |
Returns
the final result of the accumulator applied to the iterable