View source code
Display the source code in std/algorithm/iteration.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

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.

If r is empty, an Exception is thrown.

Parameters

NameDescription
r an iterable value as defined by isIterable

Returns

the final result of the accumulator applied to the iterable

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

NameDescription
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

Authors

Andrei Alexandrescu

License

Boost License 1.0.