const fileName_1 = "(@effect/core) _src/io/Schedule/operations/foldEffect.ts";
import * as tsplus_module_1 from "@tsplus/stdlib/data/Tuple/make";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/succeed";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/map";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/flatMap";
import { makeWithState } from "@effect/core/io/Schedule/operations/_internal/makeWithState";
/**
 * Returns a new schedule that effectfully folds over the outputs of this one.
 *
 * @tsplus fluent ets/Schedule foldEffect
 * @tsplus fluent ets/Schedule/WithState foldEffect
 */

export function foldEffect_(self, z, f) {
  return makeWithState(tsplus_module_1.make(self._initial, z), (now, input, {
    tuple: [s, z]
  }) => tsplus_module_4.flatMap_(self._step(now, input, s), ({
    tuple: [s, out, decision]
  }) => decision._tag === "Done" ? tsplus_module_2.succeed(() => tsplus_module_1.make(tsplus_module_1.make(s, z), z, decision), fileName_1 + ":20:27") : tsplus_module_3.map_(f(z, out), z2 => tsplus_module_1.make(tsplus_module_1.make(s, z2), z, decision), fileName_1 + ":21:26"), fileName_1 + ":18:15"));
}
/**
 * Returns a new schedule that effectfully folds over the outputs of this one.
 *
 * @tsplus static ets/Schedule/Aspects foldEffect
 */

export const foldEffect = (z, f) => self => foldEffect_(self, z, f);
//# sourceMappingURL=foldEffect.mjs.map