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

Function foldReader

packages/effect/src/internal/sink.ts:818–837  ·  view source on GitHub ↗
(
  s: S,
  contFn: Predicate<S>,
  f: (z: S, input: In) => S
)

Source from the content-addressed store, hash-verified

816
817/** @internal */
818const foldReader = <S, In>(
819 s: S,
820 contFn: Predicate<S>,
821 f: (z: S, input: In) => S
822): Channel.Channel<Chunk.Chunk<In>, Chunk.Chunk<In>, never, never, S, unknown> => {
823 if (!contFn(s)) {
824 return core.succeedNow(s)
825 }
826 return core.readWith({
827 onInput: (input: Chunk.Chunk<In>) => {
828 const [nextS, leftovers] = foldChunkSplit(s, input, contFn, f, 0, input.length)
829 if (Chunk.isNonEmpty(leftovers)) {
830 return pipe(core.write(leftovers), channel.as(nextS))
831 }
832 return foldReader(nextS, contFn, f)
833 },
834 onFailure: core.fail,
835 onDone: () => core.succeedNow(s)
836 })
837}
838
839/** @internal */
840const foldChunkSplit = <S, In>(

Callers 1

foldFunction · 0.85

Calls 3

foldChunkSplitFunction · 0.85
pipeFunction · 0.70
writeMethod · 0.65

Tested by

no test coverage detected