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

Function foldUntil

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

864 * @since 2.0.0
865 */
866export const foldUntil = <S, In, E = never, R = never>(
867 s: LazyArg<S>,
868 max: number,
869 f: (s: S, input: In) => Effect.Effect<S, E, R>
870): Sink<S, In, In, E, R> => {
871 const count = Count.normalize(max)
872 if (count === 0) return sync(s)
873 return fold<readonly [S, number], In, E, R>(
874 () => [s(), 0],
875 (tuple) => tuple[1] < count,
876 ([output, consumed], input) => Effect.map(f(output, input), (s) => [s, consumed + 1] as const)
877 ).pipe(
878 map((tuple) => tuple[0])
879 )
880}
881
882/**
883 * A sink that returns whether all elements satisfy the specified predicate.

Callers

nothing calls this directly

Calls 7

sFunction · 0.85
syncFunction · 0.70
foldFunction · 0.70
pipeMethod · 0.65
fFunction · 0.50
mapFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected