🧩 Accumulates values from an async iterator using a reducer function.
Syntax
TypeScript
import { reduceIterAsync } from '@opentf/std'; reduceIterAsync<T, U>(iter: AsyncIterable<T>, fn: (acc: U, val: T) => U | Promise<U>, initialValue: U): Promise<U>
Parameters
iter: The async iterable to reduce.fn: The reducer function.initialValue: The initial value for the accumulator.
Returns
A promise that resolves to the final accumulator value.
Examples
TypeScript
async function* gen() { yield 1; yield 2; yield 3; } await reduceIterAsync(gen(), (acc, x) => acc + x, 0) //=> 6