The type of values that iterator will yield and that initial must be
The type of values that reducer will return
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. Also returned if iterator never yields a value
const set: Set<number> = new Set([1, 2, 3, 4, 5]);
const sum = eagerlyReduceIterator(
set.values(),
(carry: number, item: number): number => {
return carry + item;
},
0,
);
// sum is now 15
Generated using TypeDoc
Given an iterator, eagerly reduce over its results until it finishes and return the result