MCPcopy
hub / github.com/Effect-TS/effect / unfoldChunk

Function unfoldChunk

packages/effect/src/internal/stream.ts:7406–7416  ·  view source on GitHub ↗
(
  s: S,
  f: (s: S) => Option.Option<readonly [Chunk.Chunk<A>, S]>
)

Source from the content-addressed store, hash-verified

7404
7405/** @internal */
7406export const unfoldChunk = <S, A>(
7407 s: S,
7408 f: (s: S) => Option.Option<readonly [Chunk.Chunk<A>, S]>
7409): Stream.Stream<A> => {
7410 const loop = (s: S): Channel.Channel<Chunk.Chunk<A>, unknown, never, unknown, unknown, unknown> =>
7411 Option.match(f(s), {
7412 onNone: () => core.void,
7413 onSome: ([chunk, s]) => core.flatMap(core.write(chunk), () => loop(s))
7414 })
7415 return new StreamImpl(core.suspend(() => loop(s)))
7416}
7417
7418/** @internal */
7419export const unfoldChunkEffect = <S, A, E, R>(

Callers 1

unfoldFunction · 0.85

Calls 1

loopFunction · 0.70

Tested by

no test coverage detected