Accumulate the values from an input stream into a single value, similar to std::accumulate.
Declared in <folly/coro/Accumulate.h>
template<
typename Reference,
typename Value,
typename Output>
Task<Output>
accumulate(
AsyncGenerator<Reference, Value> generator,
Output init);
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{});
}
A Task containing the result of the accumulation.
| Name | Description |
|---|---|
| generator | The input stream of values. |
| init | The initial value of the accumulation. |