The value returned from the iterator
The return type of your reducer function
If your iterator has a return type it must be the same as TIteratorValue, otherwise undefined
The type your iterator is expecting as what's passed to its next function. For generators this is the type returned after a yield.
The iterator you wish to reduce over
A function to use to reduce the elements iterator produces
The initial value to pass to reducer with the first element
const set: Set<number> = new Set([1, 2, 3, 4, 5]);
const summingIterator = reduceIterator(
set.values(),
(carry: number, item: number): number => {
return carry + item;
},
0,
);
// summingIterator will now yield the sum for each value seen thus far
const finalValues = Array.from(summingIterator);
// finalValues will now be [1,3,6,10,15];
Generated using TypeDoc
Given an Iterable or IterableIterator, a reducer, and an initial value, return a new IterableIterator that yields values that are automatically piped through said reducer.