asyncerator
Version:
Provide supporting types for AsyncIterable/AsyncIterableIterators, promisified stream.pipeline implementation, and Array-like utility operators, sources and sinks.
14 lines (13 loc) • 1.09 kB
TypeScript
import { type Asyncerator } from '../asyncerator';
/**
* Calls the specified callback function for all the elements in a stream. The return value of the callback function
* is the accumulated result, and is provided as an argument in the next call to the callback function.
* Equivalent to the Javascript Array.reduce() method.
*
* @param reduceFunction The reduce method calls the reduceFunction function one time for each element in the stream.
* @param initialValue If initialValue is specified, it is used as the previousValue to start the accumulation.
* Otherwise, the initial previousValue will be undefined.
*/
export type ReduceFunction<Input, Output> = (previousValue: Output, currentValue: Input, currentIndex: number) => Output;
export default function <Input>(reduceFunction: ReduceFunction<Input, Input>, initialValue?: Input): (iterator: Asyncerator<Input>) => Promise<Input | undefined>;
export default function <Input, Output>(reduceFunction: ReduceFunction<Input, Output>, initialValue?: Output): (iterator: Asyncerator<Input>) => Promise<Output | undefined>;