8 lines
210 B
TypeScript
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;
|
|
}
|