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

Function foldUntil

packages/effect/src/Sink.ts:830–841  ·  view source on GitHub ↗
(
  s: LazyArg<S>,
  max: number,
  f: (s: S, input: In) => Effect.Effect<S, E, R>
)

Source from the content-addressed store, hash-verified

828 * @since 2.0.0
829 */
830export const foldUntil = <S, In, E = never, R = never>(
831 s: LazyArg<S>,
832 max: number,
833 f: (s: S, input: In) => Effect.Effect<S, E, R>
834): Sink<S, In, In, E, R> =>
835 fold<readonly [S, number], In, E, R>(
836 () => [s(), 0],
837 (tuple) => tuple[1] < max,
838 ([output, count], input) => Effect.map(f(output, input), (s) => [s, count + 1] as const)
839 ).pipe(
840 map((tuple) => tuple[0])
841 )
842
843/**
844 * A sink that returns whether all elements satisfy the specified predicate.

Callers

nothing calls this directly

Calls 5

foldFunction · 0.85
mapFunction · 0.85
pipeMethod · 0.65
fFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected