MCPcopy Create free account
hub / github.com/Effect-TS/effect / reduceArray

Function reduceArray

packages/effect/src/Sink.ts:1473–1487  ·  view source on GitHub ↗
(
  initial: LazyArg<S>,
  f: (s: S, input: NonEmptyReadonlyArray<In>) => S
)

Source from the content-addressed store, hash-verified

1471 * @since 4.0.0
1472 */
1473export const reduceArray = <S, In>(
1474 initial: LazyArg<S>,
1475 f: (s: S, input: NonEmptyReadonlyArray<In>) => S
1476): Sink<S, In> =>
1477 fromTransform((upstream) => {
1478 let state = initial()
1479 return upstream.pipe(
1480 Effect.flatMap((arr) => {
1481 state = f(state, arr)
1482 return Effect.void
1483 }),
1484 Effect.forever({ disableYield: true }),
1485 Pull.catchDone(() => Effect.succeed([state] as const))
1486 )
1487 })
1488
1489/**
1490 * A sink that reduces its inputs using the provided effectful function `f`

Callers 3

reduceFunction · 0.85
Sink.tsFile · 0.85
collectFunction · 0.85

Calls 5

fromTransformFunction · 0.70
pipeMethod · 0.65
initialFunction · 0.50
fFunction · 0.50
succeedMethod · 0.45

Tested by

no test coverage detected