Accumulate the values from an input stream into a single value, similar to std::accumulate.

Synopsis

Declared in <folly/coro/Accumulate.h>

template<
    typename Reference,
    typename Value,
    typename Output>
Task<Output>
accumulate(
    AsyncGenerator<Reference, Value> generator,
    Output init);

Description

The input is a stream of values and the output is a Task containing the result of the accumulation.

Example:

AsyncGenerator<int> stream();

Task<void> consumer() {
  auto sum = co_await accumulate(stream(), 0, std::plus{});
}

Return Value

A Task containing the result of the accumulation.

Parameters

Name

Description

generator

The input stream of values.

init

The initial value of the accumulation.

Created with MrDocs