Reduce the values of an (async)iterable to a single value.
import reduce from 'it-reduce'// This can also be an iterator, generator, etcconst values = [0, 1, 2, 3, 4]const result = reduce(values, (acc, curr, index) => acc + curr, 0)console.info(result) // 10 Copy
import reduce from 'it-reduce'// This can also be an iterator, generator, etcconst 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:
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 Copy
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
Reduce the values of an (async)iterable to a single value.
Example
Async sources must be awaited: