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

Function paginateChunk

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

Source from the content-addressed store, hash-verified

4533
4534/** @internal */
4535export const paginateChunk = <S, A>(
4536 s: S,
4537 f: (s: S) => readonly [Chunk.Chunk<A>, Option.Option<S>]
4538): Stream.Stream<A> => {
4539 const loop = (s: S): Channel.Channel<Chunk.Chunk<A>, unknown, never, unknown, unknown, unknown> => {
4540 const page = f(s)
4541 return Option.match(page[1], {
4542 onNone: () => channel.zipRight(core.write(page[0]), core.void),
4543 onSome: (s) => core.flatMap(core.write(page[0]), () => loop(s))
4544 })
4545 }
4546 return new StreamImpl(core.suspend(() => loop(s)))
4547}
4548
4549/** @internal */
4550export const paginateChunkEffect = <S, A, E, R>(

Callers 1

paginateFunction · 0.85

Calls 1

loopFunction · 0.70

Tested by

no test coverage detected