import * as tsplus_module_1 from "@effect/core/io/Schedule/operations/driver";
import * as tsplus_module_2 from "@effect/core/io/Effect/operations/flatMap";
import * as tsplus_module_3 from "@effect/core/io/Effect/operations/suspendSucceed";
import * as tsplus_module_4 from "@effect/core/io/Effect/operations/orDie";
import * as tsplus_module_5 from "@effect/core/io/Effect/operations/foldEffect";
export const scheduleFrom_ = scheduleFrom_1;
/**
 * Runs this effect according to the specified schedule.
 *
 * See `scheduleFrom` for a variant that allows the schedule's decision to
 * depend on the result of this effect.
 *
 * @tsplus fluent ets/Effect scheduleFrom
 */

function scheduleFrom_1(self, a, schedule, __tsplusTrace) {
  return tsplus_module_3.suspendSucceed(() => {
    const schedule0 = schedule();
    const value = a();
    return tsplus_module_2.flatMap_(tsplus_module_1.driver(schedule0), scheduleFromLoop(self, value, __tsplusTrace), __tsplusTrace);
  }, __tsplusTrace);
}
/**
 * Runs this effect according to the specified schedule.
 *
 * See `scheduleFrom` for a variant that allows the schedule's decision to
 * depend on the result of this effect.
 *
 * @tsplus static ets/Effect/Aspects scheduleFrom
 */


export function scheduleFrom(a, schedule, __tsplusTrace) {
  return self => scheduleFrom_1(self, a, schedule, __tsplusTrace);
}

function scheduleFromLoop(self, value, __tsplusTrace) {
  return driver => tsplus_module_5.foldEffect_(driver.next(value), () => tsplus_module_4.orDie(driver.last, __tsplusTrace), () => tsplus_module_2.flatMap_(self, a => scheduleFromLoop(self, a, __tsplusTrace)(driver), __tsplusTrace), __tsplusTrace);
}
//# sourceMappingURL=scheduleFrom.mjs.map