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

Function unfoldChunkEffect

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

Source from the content-addressed store, hash-verified

7455
7456/** @internal */
7457export const unfoldChunkEffect = <S, A, E, R>(
7458 s: S,
7459 f: (s: S) => Effect.Effect<Option.Option<readonly [Chunk.Chunk<A>, S]>, E, R>
7460): Stream.Stream<A, E, R> =>
7461 suspend(() => {
7462 const loop = (s: S): Channel.Channel<Chunk.Chunk<A>, unknown, E, unknown, unknown, unknown, R> =>
7463 channel.unwrap(
7464 Effect.map(
7465 f(s),
7466 Option.match({
7467 onNone: () => core.void,
7468 onSome: ([chunk, s]) => core.flatMap(core.write(chunk), () => loop(s))
7469 })
7470 )
7471 )
7472 return new StreamImpl(loop(s))
7473 })
7474
7475/** @internal */
7476export const unfoldEffect = <S, A, E, R>(

Callers 3

stream.tsFile · 0.85
repeatEffectChunkOptionFunction · 0.85
unfoldEffectFunction · 0.85

Calls 2

suspendFunction · 0.70
loopFunction · 0.70

Tested by

no test coverage detected