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

Function foldArray

packages/effect/src/Sink.ts:830–847  ·  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

828 * @since 4.0.0
829 */
830export const foldArray = <S, In, E = never, R = never>(
831 s: LazyArg<S>,
832 contFn: Predicate<S>,
833 f: (s: S, input: Arr.NonEmptyReadonlyArray<In>) => Effect.Effect<S, E, R>
834): Sink<S, In, never, E, R> =>
835 fromTransform((upstream) => {
836 let state = s()
837 return Effect.gen(function*() {
838 while (true) {
839 const arr = yield* upstream
840 state = yield* f(state, arr)
841 if (contFn(state)) continue
842 return [state] as const
843 }
844 }).pipe(
845 Pull.catchDone(() => Effect.succeed<End<S>>([state]))
846 )
847 })
848
849/**
850 * Folds input elements into state until the specified maximum number of

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected