import { StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal" /** * Like `unfoldChunkEffect`, 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 paginateChunkEffect */ export function paginateChunkEffect( s: S, f: (s: S) => Effect, Maybe]> ): Stream { return new StreamInternal(Channel.suspend(loop(s, f))) } function loop( s: S, f: (s: S) => Effect, Maybe]> ): Channel, unknown> { return Channel.unwrap( f(s).map(([as, maybeS]) => maybeS.fold( Channel.write(as).zipRight(Channel.unit), (s) => Channel.write(as).zipRight(loop(s, f)) ) ) ) }