MCPcopy Index your code
hub / github.com/Effect-TS/effect / foldEffectReader

Function foldEffectReader

packages/effect/src/internal/sink.ts:991–1016  ·  view source on GitHub ↗
(
  s: S,
  contFn: Predicate<S>,
  f: (s: S, input: In) => Effect.Effect<S, E, R>
)

Source from the content-addressed store, hash-verified

989
990/** @internal */
991const foldEffectReader = <S, In, R, E>(
992 s: S,
993 contFn: Predicate<S>,
994 f: (s: S, input: In) => Effect.Effect<S, E, R>
995): Channel.Channel<Chunk.Chunk<In>, Chunk.Chunk<In>, E, E, S, unknown, R> => {
996 if (!contFn(s)) {
997 return core.succeedNow(s)
998 }
999 return core.readWith({
1000 onInput: (input: Chunk.Chunk<In>) =>
1001 pipe(
1002 core.fromEffect(foldChunkSplitEffect(s, input, contFn, f)),
1003 core.flatMap(([nextS, leftovers]) =>
1004 pipe(
1005 leftovers,
1006 Option.match({
1007 onNone: () => foldEffectReader(nextS, contFn, f),
1008 onSome: (leftover) => pipe(core.write(leftover), channel.as(nextS))
1009 })
1010 )
1011 )
1012 ),
1013 onFailure: core.fail,
1014 onDone: () => core.succeedNow(s)
1015 })
1016}
1017
1018/** @internal */
1019const foldChunkSplitEffect = <S, R, E, In>(

Callers 1

foldEffectFunction · 0.85

Calls 4

foldChunkSplitEffectFunction · 0.85
fromEffectMethod · 0.80
pipeFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected