const fileName_1 = "(@effect/core) _src/stream/Stream/operations/unfoldChunkEffect.ts";
import * as tsplus_module_1 from "@effect/core/stream/Channel/operations/unit";
import * as tsplus_module_2 from "@effect/core/stream/Channel/operations/write";
import * as tsplus_module_3 from "@effect/core/stream/Channel/operations/zipRight";
import * as tsplus_module_4 from "@tsplus/stdlib/data/Maybe/fold";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_6 from "@effect/core/stream/Channel/operations/unwrap";
import { StreamInternal } from "@effect/core/stream/Stream/operations/_internal/StreamInternal";
/**
 * Creates a stream by effectfully peeling off the "layers" of a value of type
 * `S`.
 *
 * @tsplus static ets/Stream/Ops unfoldChunkEffect
 */

export function unfoldChunkEffect(s, f) {
  return new StreamInternal(loop(s, f));
}

function loop(s, f) {
  return tsplus_module_6.unwrap(() => tsplus_module_5.map_(f(s()), option => tsplus_module_4.fold_(option, () => tsplus_module_1.unit, ({
    tuple: [as, s]
  }) => tsplus_module_3.zipRight_(tsplus_module_2.write(() => as), () => loop(() => s, f))), fileName_1 + ":21:15"));
}
//# sourceMappingURL=unfoldChunkEffect.mjs.map