Files
sequence.ts/src/sequence/fold.ts
2026-04-25 19:45:36 +02:00

8 lines
210 B
TypeScript

export function fold<T, R>(value: Iterable<T>, initial: R, accumulate: (acc: R, it: T) => R): R {
let acc = initial;
for (const it of value) {
acc = accumulate(acc, it);
}
return acc;
}