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

Function paginateChunkEffect

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

Source from the content-addressed store, hash-verified

4548
4549/** @internal */
4550export const paginateChunkEffect = <S, A, E, R>(
4551 s: S,
4552 f: (s: S) => Effect.Effect<readonly [Chunk.Chunk<A>, Option.Option<S>], E, R>
4553): Stream.Stream<A, E, R> => {
4554 const loop = (s: S): Channel.Channel<Chunk.Chunk<A>, unknown, E, unknown, unknown, unknown, R> =>
4555 channel.unwrap(
4556 Effect.map(f(s), ([chunk, option]) =>
4557 Option.match(option, {
4558 onNone: () => channel.zipRight(core.write(chunk), core.void),
4559 onSome: (s) => core.flatMap(core.write(chunk), () => loop(s))
4560 }))
4561 )
4562 return new StreamImpl(core.suspend(() => loop(s)))
4563}
4564
4565/** @internal */
4566export const paginateEffect = <S, A, E, R>(

Callers 1

paginateEffectFunction · 0.85

Calls 1

loopFunction · 0.70

Tested by

no test coverage detected