import { StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal" /** * Like `unfoldChunk`, but allows the emission of values to end one step * further than the unfolding of the state. This is useful for embedding * paginated APIs, hence the name. * * @tsplus static effect/core/stream/Stream.Ops paginateChunk */ export function paginateChunk( s: S, f: (s: S) => readonly [Chunk, Maybe] ): Stream { return new StreamInternal(Channel.suspend(loop(s, f))) } function loop( s: S, f: (s: S) => readonly [Chunk, Maybe] ): Channel, unknown> { const [as, maybeS] = f(s) return maybeS.fold( Channel.write(as).zipRight(Channel.unit), (s) => Channel.write(as).zipRight(loop(s, f)) ) }