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

Function unfoldChunk

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

Source from the content-addressed store, hash-verified

7442
7443/** @internal */
7444export const unfoldChunk = <S, A>(
7445 s: S,
7446 f: (s: S) => Option.Option<readonly [Chunk.Chunk<A>, S]>
7447): Stream.Stream<A> => {
7448 const loop = (s: S): Channel.Channel<Chunk.Chunk<A>, unknown, never, unknown, unknown, unknown> =>
7449 Option.match(f(s), {
7450 onNone: () => core.void,
7451 onSome: ([chunk, s]) => core.flatMap(core.write(chunk), () => loop(s))
7452 })
7453 return new StreamImpl(core.suspend(() => loop(s)))
7454}
7455
7456/** @internal */
7457export const unfoldChunkEffect = <S, A, E, R>(

Callers 1

unfoldFunction · 0.85

Calls 1

loopFunction · 0.70

Tested by

no test coverage detected