MCPcopy Create free account
hub / github.com/effect-app/libs / foldArray

Function foldArray

repos/effect/packages/effect/src/Sink.ts:767–784  ·  view source on GitHub ↗
(
  s: LazyArg<S>,
  contFn: Predicate<S>,
  f: (s: S, input: Arr.NonEmptyReadonlyArray<In>) => Effect.Effect<S, E, R>
)

Source from the content-addressed store, hash-verified

765 const arr = yield* upstream
766 for (let i = 0; i < arr.length; i++) {
767 state = yield* f(state, arr[i])
768 if (contFn(state)) continue
769 return [
770 state,
771 (i + 1) < arr.length ? (arr.slice(i + 1) as any) : undefined
772 ] as const
773 }
774 }
775 }).pipe(
776 Pull.catchDone(() => Effect.succeed<End<S, In>>([state]))
777 )
778 })
779
780/**
781 * Folds non-empty input arrays into state with an effectful function.
782 *
783 * **When to use**
784 *
785 * Use to update state with an effectful function once per pulled non-empty
786 * input array when batch-level processing is the natural unit.
787 *

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…