MCPcopy
hub / github.com/Effect-TS/effect / reduce

Function reduce

packages/typeclass/src/internal/Iterable.ts:2–13  ·  view source on GitHub ↗
(b: B, f: (s: B, a: A) => B)

Source from the content-addressed store, hash-verified

1/** @internal */
2export function reduce<A, B>(b: B, f: (s: B, a: A) => B) {
3 return function(iterable: Iterable<A>): B {
4 if (Array.isArray(iterable)) {
5 return iterable.reduce(f, b)
6 }
7 let result = b
8 for (const n of iterable) {
9 result = f(result, n)
10 }
11 return result
12 }
13}
14
15/** @internal */
16export function map<A, B>(f: (a: A) => B) {

Callers 2

Foldable.test.tsFile · 0.50
makeFunction · 0.50

Calls 1

fFunction · 0.50

Tested by

no test coverage detected