UNPKG

it-reduce

Version:

Reduces the values yielded from an async iterator

39 lines 1.02 kB
/** * @packageDocumentation * * Reduce the values of an (async)iterable to a single value. * * @example * * ```javascript * import reduce from 'it-reduce' * * // This can also be an iterator, generator, etc * const values = [0, 1, 2, 3, 4] * * const result = reduce(values, (acc, curr, index) => acc + curr, 0) * * console.info(result) // 10 * ``` * * Async sources must be awaited: * * ```javascript * import reduce from 'it-reduce' * * const values = async function * () { * yield * [0, 1, 2, 3, 4] * } * * const result = await reduce(values(), (acc, curr, index) => acc + curr, 0) * * console.info(result) // 10 * ``` */ /** * Reduces the values yielded by an (async) iterable */ declare function reduce<T, V>(source: Iterable<T>, func: (acc: V, curr: T, index: number) => V, init: V): V; declare function reduce<T, V>(source: Iterable<T> | AsyncIterable<T>, func: (acc: V, curr: T, index: number) => V, init: V): Promise<V>; export default reduce; //# sourceMappingURL=index.d.ts.map