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

Function foldArray

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

797 * @since 4.0.0
798 */
799export const foldArray = <S, In, E = never, R = never>(
800 s: LazyArg<S>,
801 contFn: Predicate<S>,
802 f: (s: S, input: Arr.NonEmptyReadonlyArray<In>) => Effect.Effect<S, E, R>
803): Sink<S, In, never, E, R> =>
804 fromTransform((upstream) => {
805 let state = s()
806 return Effect.gen(function*() {
807 while (true) {
808 const arr = yield* upstream
809 state = yield* f(state, arr)
810 if (contFn(state)) continue
811 return [state] as const
812 }
813 }).pipe(
814 Pull.catchDone(() => Effect.succeed<End<S>>([state]))
815 )
816 })
817
818/**
819 * Folds input elements into state until the specified maximum number of

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