import { StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal" /** * Creates a stream by peeling off the "layers" of a value of type `S`. * * @tsplus static effect/core/stream/Stream.Ops unfoldChunk */ export function unfoldChunk( s: S, f: (s: S) => Maybe, S]> ): Stream { return new StreamInternal(Channel.suspend(loop(s, f))) } function loop( s: S, f: (s: S) => Maybe, S]> ): Channel, unknown> { return f(s).fold( Channel.unit, ([as, s]) => Channel.write(as).flatMap(() => loop(s, f)) ) }