"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.flipWith_ = exports.flip = exports.chainError = exports.chainError_ = exports.first = exports.eventually = exports.either = exports.compose_ = exports.compose = exports.provide = exports.continueOrFail = exports.continueOrFail_ = exports.continueOrFailM = exports.continueOrFailM_ = exports.catchSomeCause = exports.catchSomeCause_ = exports.catchSome = exports.catchSome_ = exports.catchAllCause = exports.catchAllCause_ = exports.catchAll = exports.catchAll_ = exports.orElseSucceed = exports.orElseSucceed_ = exports.orElseOptional = exports.orElseOptional_ = exports.orElseEither_ = exports.orElseEither = exports.orElseFail_ = exports.orElseFail = exports.orElse_ = exports.orElse = exports.orDie = exports.orDieWith_ = exports.orDieWith = exports.optional = exports.option = exports.fold = exports.fold_ = exports.none = exports.unit = exports.merge = exports.memoize = exports.mapErrorCause = exports.mapErrorCause_ = exports.mapError = exports.mapError_ = exports.get = exports.absorb_ = exports.absorb = void 0;
exports.someOrElse_ = exports.someOrElse = exports.some = exports.second = exports.sandboxWith_ = exports.sandboxWith = exports.unsandbox = exports.sandbox = exports.result = exports.retry = exports.retry_ = exports.retryOrElse = exports.retryOrElse_ = exports.retryOrElseEither = exports.retryOrElseEither_ = exports.release = exports.reject_ = exports.reject = exports.rejectM_ = exports.rejectM = exports.dieMessage = exports.dieWith = exports.die = exports.refineOrDie_ = exports.refineOrDie = exports.refineOrDieWith_ = exports.refineOrDieWith = exports.provideSomeLayer = exports.provideLayer_ = exports.provideLayer = exports.preallocateManaged = exports.preallocate = exports.mapEffect = exports.mapEffect_ = exports.mapTryCatch_ = exports.mapTryCatch = exports.tryCatch = exports.identityLeft = exports.joinEither_ = exports.joinEither = exports.join_ = exports.join = exports.isSuccess = exports.isFailure = exports.ignore = exports.foldCause = exports.foldCause_ = exports.flattenM = exports.flatten = exports.flipWith = void 0;
exports.replaceServiceM = exports.provideService = exports.provideServiceM = exports.services = exports.service = exports.accessService = exports.accessServiceM = exports.accessServices = exports.accessServicesT = exports.accessServicesTM = exports.accessServicesM = exports.accessM = exports.accessManaged = exports.access = exports.left = exports.right = exports.bimap_ = exports.bimap = exports.andThen = exports.andThen_ = exports.asService_ = exports.asService = exports.asSomeError = exports.asSome = exports.as = exports.as_ = exports.unless_ = exports.unless = exports.unlessM_ = exports.unlessM = exports.asUnit = exports.toLayerMany = exports.toLayer_ = exports.toLayer = exports.timeout = exports.timeout_ = exports.timed = exports.tapM_ = exports.tapM = exports.tapError = exports.tapError_ = exports.tapCause = exports.tapCause_ = exports.tapBoth = exports.tapBoth_ = exports.someOrFailException = exports.someOrFail_ = exports.someOrFail = exports.someOrElseM_ = exports.someOrElseM = void 0;
exports.collectAllSuccessesParN_ = exports.collectAllSuccessesParN = exports.collectAllSuccessesPar = exports.collectAllSuccesses = exports.collectAllWithParN = exports.collectAllWithParN_ = exports.collectAllWithPar = exports.collectAllWithPar_ = exports.collectAllWith = exports.collectAllWith_ = exports.collectAllUnitParN_ = exports.collectAllUnitParN = exports.collectAllUnitPar = exports.collectAllUnit = exports.collectAllParN_ = exports.collectAllParN = exports.collectAllPar = exports.collectAll = exports.collectParN = exports.collectParN_ = exports.collectPar_ = exports.collectPar = exports.collect_ = exports.collect = exports.forEachUnitParN = exports.forEachUnitParN_ = exports.forEachUnitPar = exports.forEachUnitPar_ = exports.cond = exports.cond_ = exports.create = exports.zipPar = exports.zipPar_ = exports.zipRightPar = exports.zipRightPar_ = exports.zipRight = exports.zipRight_ = exports.zipLeftPar = exports.zipLeftPar_ = exports.zipLeft = exports.zipLeft_ = exports.withEarlyRelease = exports.fiberId = exports.withEarlyReleaseExit = exports.withEarlyReleaseExit_ = exports.when = exports.whenM = exports.replaceService_ = exports.replaceService = exports.replaceServiceM_ = void 0;
exports.exposeTracer = exports.interruptAs = exports.interrupt = exports.fromAutoClosableM = exports.fromAutoClosable = exports.unwrap = exports.withChildren = exports.scope = exports.mergeAllParN_ = exports.mergeAllParN = exports.mergeAllPar_ = exports.mergeAllPar = exports.mergeAll_ = exports.mergeAll = exports.reduceAllParN = exports.reduceAllParN_ = exports.reduceAllPar = exports.reduceAllPar_ = exports.reduceAll = exports.reduceAll_ = exports.reduceRight = exports.reduceRight_ = exports.reduce = exports.reduce_ = exports.finalizer = exports.finalizerExit = void 0;
const C = __importStar(require("../../Cause"));
const Cause_1 = require("../../Cause");
const A = __importStar(require("../../Collections/Immutable/Array"));
const Chunk = __importStar(require("../../Collections/Immutable/Chunk"));
const R = __importStar(require("../../Collections/Immutable/Dictionary"));
const NA = __importStar(require("../../Collections/Immutable/NonEmptyArray"));
const SS = __importStar(require("../../Collections/Immutable/SortedSet"));
const Tp = __importStar(require("../../Collections/Immutable/Tuple"));
const T = __importStar(require("../../Effect"));
const primitives_1 = require("../../Effect/primitives");
const E = __importStar(require("../../Either"));
const Ex = __importStar(require("../../Exit"));
const F = __importStar(require("../../Fiber"));
const Function_1 = require("../../Function");
const GlobalExceptions_1 = require("../../GlobalExceptions");
const Has_1 = require("../../Has");
const I = __importStar(require("../../Iterable"));
const L = __importStar(require("../../Layer"));
const O = __importStar(require("../../Option"));
const P = __importStar(require("../../Promise"));
const Supervisor_1 = require("../../Supervisor");
const core = __importStar(require("../core"));
const forEach = __importStar(require("../forEach"));
const fromEffect_1 = require("../fromEffect");
const makeExit_1 = require("../makeExit");
const managed_1 = require("../managed");
const add = __importStar(require("../ReleaseMap/add"));
const makeReleaseMap = __importStar(require("../ReleaseMap/makeReleaseMap"));
const releaseAll = __importStar(require("../ReleaseMap/releaseAll"));
const succeed_1 = require("../succeed");
const absolve_1 = require("./absolve");
const environment_1 = require("./environment");
const foldM_1 = require("./foldM");
const halt_1 = require("./halt");
const releaseMap_1 = require("./releaseMap");
const suspend_1 = require("./suspend");
/**
 * Attempts to convert defects into a failure, throwing away all information
 * about the cause of the failure.
 *
 * @ets_data_first absorb_
 */
function absorb(f, __trace) {
    return (self) => absorb_(self, f, __trace);
}
exports.absorb = absorb;
/**
 * Attempts to convert defects into a failure, throwing away all information
 * about the cause of the failure.
 */
function absorb_(self, f, __trace) {
    return (0, foldM_1.foldM_)(sandbox(self), (c) => core.fail(C.squash(f)(c)), succeed_1.succeed, __trace);
}
exports.absorb_ = absorb_;
/**
 * Unwraps the optional success of this effect, but can fail with None value.
 */
function get(self, __trace) {
    return (0, absolve_1.absolve)(core.map_(self, E.fromOption(() => O.none)), __trace);
}
exports.get = get;
/**
 * Returns an effect whose failure is mapped by the specified `f` function.
 */
function mapError_(self, f, __trace) {
    return (0, managed_1.managedApply)(T.mapError_(self.effect, f, __trace));
}
exports.mapError_ = mapError_;
/**
 * Returns an effect whose failure is mapped by the specified `f` function.
 *
 * @ets_data_first mapError_
 */
function mapError(f, __trace) {
    return (self) => mapError_(self, f, __trace);
}
exports.mapError = mapError;
/**
 * Returns an effect whose full failure is mapped by the specified `f` function.
 */
function mapErrorCause_(self, f, __trace) {
    return (0, managed_1.managedApply)(T.mapErrorCause_(self.effect, f, __trace));
}
exports.mapErrorCause_ = mapErrorCause_;
/**
 * Returns an effect whose full failure is mapped by the specified `f` function.
 *
 * @ets_data_first mapErrorCause_
 */
function mapErrorCause(f, __trace) {
    return (self) => mapErrorCause_(self, f, __trace);
}
exports.mapErrorCause = mapErrorCause;
/**
 * Returns a memoized version of the specified managed.
 */
function memoize(self, __trace) {
    return core.mapM_(releaseMap_1.releaseMap, (finalizers) => (T.map_(T.bind_(T.bind_(T.do, "promise", () => P.make()), "complete", ({ promise }) => T.once(T.accessM((r) => (T.to_(T.map_(T.provideAll_(self.effect, Tp.tuple(r, finalizers)), (_) => _.get(1)), promise))))), ({ complete, promise }) => (T.toManaged(T.zipRight_(complete, P.await(promise)))))), __trace);
}
exports.memoize = memoize;
/**
 * Returns a new effect where the error channel has been merged into the
 * success channel to their common combined type.
 */
function merge(self, __trace) {
    return (0, foldM_1.foldM_)(self, succeed_1.succeed, succeed_1.succeed, __trace);
}
exports.merge = merge;
/**
 * Returns the managed resulting from mapping the success of this managed to unit.
 */
exports.unit = (0, suspend_1.suspend)(() => (0, fromEffect_1.fromEffect)(T.unit));
/**
 * Requires the option produced by this value to be `None`.
 */
function none(self, __trace) {
    return (0, foldM_1.foldM_)(self, (x) => (core.fail(O.some(x))), O.fold(() => exports.unit, () => core.fail(O.none)), __trace);
}
exports.none = none;
/**
 * Folds over the failure value or the success value to yield an effect that
 * does not fail, but succeeds with the value returned by the left or right
 * function passed to `fold`.
 */
function fold_(self, onFail, onSuccess, __trace) {
    return (0, foldM_1.foldM_)(self, (x) => ((0, succeed_1.succeed)(onFail(x))), (x) => ((0, succeed_1.succeed)(onSuccess(x))), __trace);
}
exports.fold_ = fold_;
/**
 * Folds over the failure value or the success value to yield an effect that
 * does not fail, but succeeds with the value returned by the left or right
 * function passed to `fold`.
 *
 * @ets_data_first fold_
 */
function fold(onFail, onSuccess, __trace) {
    return (self) => fold_(self, onFail, onSuccess, __trace);
}
exports.fold = fold;
/**
 * Executes this effect, skipping the error but returning optionally the success.
 */
function option(self, __trace) {
    return fold_(self, () => O.none, O.some, __trace);
}
exports.option = option;
/**
 * Converts an option on errors into an option on values.
 */
function optional(self, __trace) {
    return (0, foldM_1.foldM_)(self, O.fold(() => (0, succeed_1.succeed)(O.none), core.fail), (x) => ((0, succeed_1.succeed)(O.some(x))), __trace);
}
exports.optional = optional;
/**
 * Keeps none of the errors, and terminates the fiber with them, using
 * the specified function to convert the `E` into a `Throwable`.
 *
 * @ets_data_first orDieWith_
 */
function orDieWith(f, __trace) {
    return (self) => orDieWith_(self, f, __trace);
}
exports.orDieWith = orDieWith;
/**
 * Keeps none of the errors, and terminates the fiber with them, using
 * the specified function to convert the `E` into a `Throwable`.
 */
function orDieWith_(self, f, __trace) {
    return (0, managed_1.managedApply)(T.orDieWith_(self.effect, f, __trace));
}
exports.orDieWith_ = orDieWith_;
/**
 * Translates effect failure into death of the fiber, making all failures unchecked and
 * not a part of the type of the effect.
 */
function orDie(self, __trace) {
    return orDieWith_(self, Function_1.identity, __trace);
}
exports.orDie = orDie;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise executes the specified effect.
 *
 * @ets_data_first orElse_
 */
function orElse(that, __trace) {
    return (self) => orElse_(self, that, __trace);
}
exports.orElse = orElse;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise executes the specified effect.
 */
function orElse_(self, that, __trace) {
    return (0, foldM_1.foldM_)(self, () => that(), succeed_1.succeed, __trace);
}
exports.orElse_ = orElse_;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise fails with the specified error.
 *
 * @ets_data_first orElseFail_
 */
function orElseFail(e, __trace) {
    return (self) => orElseFail_(self, e, __trace);
}
exports.orElseFail = orElseFail;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise fails with the specified error.
 */
function orElseFail_(self, e, __trace) {
    return orElse_(self, () => core.fail(e), __trace);
}
exports.orElseFail_ = orElseFail_;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise executes the specified effect.
 *
 * @ets_data_first orElseEither_
 */
function orElseEither(that, __trace) {
    return (self) => orElseEither_(self, that, __trace);
}
exports.orElseEither = orElseEither;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise executes the specified effect.
 */
function orElseEither_(self, that, __trace) {
    return (0, foldM_1.foldM_)(self, () => core.map_(that(), E.left), (x) => ((0, succeed_1.succeed)(E.right(x))), __trace);
}
exports.orElseEither_ = orElseEither_;
/**
 * Returns an effect that will produce the value of this effect, unless it
 * fails with the `None` value, in which case it will produce the value of
 * the specified effect.
 */
function orElseOptional_(self, that, __trace) {
    return catchAll_(self, O.fold(() => that(), (e) => core.fail(O.some(e))), __trace);
}
exports.orElseOptional_ = orElseOptional_;
/**
 * Returns an effect that will produce the value of this effect, unless it
 * fails with the `None` value, in which case it will produce the value of
 * the specified effect.
 *
 * @ets_data_first orElseOptional_
 */
function orElseOptional(that, __trace) {
    return (self) => orElseOptional_(self, that, __trace);
}
exports.orElseOptional = orElseOptional;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise succeeds with the specified value.
 */
function orElseSucceed_(self, that, __trace) {
    return orElse_(self, () => (0, succeed_1.succeed)(that()), __trace);
}
exports.orElseSucceed_ = orElseSucceed_;
/**
 * Executes this effect and returns its value, if it succeeds, but
 * otherwise succeeds with the specified value.
 *
 * @ets_data_first orElseSucceed_
 */
function orElseSucceed(that, __trace) {
    return (self) => orElseSucceed_(self, that, __trace);
}
exports.orElseSucceed = orElseSucceed;
/**
 * Recovers from all errors.
 */
function catchAll_(self, f, __trace) {
    return (0, foldM_1.foldM_)(self, f, succeed_1.succeed, __trace);
}
exports.catchAll_ = catchAll_;
/**
 * Recovers from all errors.
 *
 * @ets_data_first catchAll_
 */
function catchAll(f, __trace) {
    return (self) => catchAll_(self, f, __trace);
}
exports.catchAll = catchAll;
/**
 * Recovers from all errors with provided Cause.
 */
function catchAllCause_(self, f, __trace) {
    return core.foldCauseM_(self, f, succeed_1.succeed, __trace);
}
exports.catchAllCause_ = catchAllCause_;
/**
 * Recovers from all errors with provided Cause.
 *
 * @ets_data_first catchAllCause_
 */
function catchAllCause(f, __trace) {
    return (self) => core.foldCauseM_(self, f, succeed_1.succeed, __trace);
}
exports.catchAllCause = catchAllCause;
/**
 * Recovers from some or all of the error cases.
 */
function catchSome_(self, pf, __trace) {
    return catchAll_(self, (e) => O.getOrElse_(pf(e), () => core.fail(e)), __trace);
}
exports.catchSome_ = catchSome_;
/**
 * Recovers from some or all of the error cases.
 *
 * @ets_data_first catchSome_
 */
function catchSome(pf, __trace) {
    return (self) => catchSome_(self, pf, __trace);
}
exports.catchSome = catchSome;
/**
 * Recovers from some or all of the error cases.
 */
function catchSomeCause_(self, pf, __trace) {
    return catchAllCause_(self, (e) => O.getOrElse_(pf(e), () => (0, halt_1.halt)(e)), __trace);
}
exports.catchSomeCause_ = catchSomeCause_;
/**
 * Recovers from some or all of the error cases.
 *
 * @ets_data_first catchSomeCause_
 */
function catchSomeCause(pf, __trace) {
    return (self) => catchSomeCause_(self, pf, __trace);
}
exports.catchSomeCause = catchSomeCause;
/**
 * Fail with `e` if the supplied `PartialFunction` does not match, otherwise
 * continue with the returned value.
 */
function continueOrFailM_(self, e, pf, __trace) {
    return core.chain_(self, (a) => O.getOrElse_(pf(a), () => core.fail(e())), __trace);
}
exports.continueOrFailM_ = continueOrFailM_;
/**
 * Fail with `e` if the supplied `PartialFunction` does not match, otherwise
 * continue with the returned value.
 *
 * @ets_data_first continueOrFailM_
 */
function continueOrFailM(e, pf, __trace) {
    return (self) => continueOrFailM_(self, e, pf, __trace);
}
exports.continueOrFailM = continueOrFailM;
/**
 * Fail with `e` if the supplied `PartialFunction` does not match, otherwise
 * succeed with the returned value.
 */
function continueOrFail_(self, e, pf, __trace) {
    return continueOrFailM_(self, e, (x) => (O.map_(pf(x), succeed_1.succeed)), __trace);
}
exports.continueOrFail_ = continueOrFail_;
/**
 * Fail with `e` if the supplied `PartialFunction` does not match, otherwise
 * succeed with the returned value.
 *
 * @ets_data_first continueOrFail_
 */
function continueOrFail(e, pf, __trace) {
    return (self) => continueOrFail_(self, e, pf, __trace);
}
exports.continueOrFail = continueOrFail;
/**
 * Provides some of the environment required to run this effect,
 * leaving the remainder `R0` and combining it automatically using spread.
 */
function provide(r, __trace) {
    return (next) => core.provideSome_(next, (r0) => ({ ...r0, ...r }), __trace);
}
exports.provide = provide;
/**
 * Executes the second effect and then provides its output as an environment to this effect
 *
 * @ets_data_first compose_
 */
function compose(that, __trace) {
    return (self) => compose_(self, that, __trace);
}
exports.compose = compose;
/**
 * Executes the second effect and then provides its output as an environment to this effect
 */
function compose_(self, that, __trace) {
    return (core.chain_((0, environment_1.environment)(), (r1) => (core.chain_(core.provideAll_(self, r1), (r) => core.provideAll_(that, r)))));
}
exports.compose_ = compose_;
/**
 * Returns an effect whose failure and success have been lifted into an
 * `Either`. The resulting effect cannot fail
 */
function either(self, __trace) {
    return fold_(self, E.left, E.right, __trace);
}
exports.either = either;
/**
 * Returns a Managed that ignores errors raised by the acquire effect and
 * runs it repeatedly until it eventually succeeds.
 */
function eventually(self, __trace) {
    return (0, managed_1.managedApply)(T.eventually(self.effect, __trace));
}
exports.eventually = eventually;
/**
 * Zips this effect with its environment
 */
function first(self, __trace) {
    return core.zip_(self, (0, environment_1.environment)(), __trace);
}
exports.first = first;
/**
 * Effectfully map the error channel
 */
function chainError_(self, f, __trace) {
    return flipWith_(self, core.chain(f, __trace));
}
exports.chainError_ = chainError_;
/**
 * Effectfully map the error channel
 *
 * @ets_data_first chainError_
 */
function chainError(f, __trace) {
    return (self) => chainError_(self, f, __trace);
}
exports.chainError = chainError;
/**
 * Flip the error and result
 */
function flip(self, __trace) {
    return (0, foldM_1.foldM_)(self, succeed_1.succeed, core.fail, __trace);
}
exports.flip = flip;
/**
 * Flip the error and result, then apply an effectful function to the effect
 */
function flipWith_(self, f, __trace) {
    return flip(f(flip(self)), __trace);
}
exports.flipWith_ = flipWith_;
/**
 * Flip the error and result, then apply an effectful function to the effect
 *
 * @ets_data_first flipWith_
 */
function flipWith(f, __trace) {
    return (self) => flipWith_(self, f, __trace);
}
exports.flipWith = flipWith;
/**
 * Returns an effect that performs the outer effect first, followed by the
 * inner effect, yielding the value of the inner effect.
 *
 * This method can be used to "flatten" nested effects.
 */
function flatten(self, __trace) {
    return core.chain_(self, Function_1.identity, __trace);
}
exports.flatten = flatten;
/**
 * Returns an effect that performs the outer effect first, followed by the
 * inner effect, yielding the value of the inner effect.
 *
 * This method can be used to "flatten" nested effects.
 */
function flattenM(self, __trace) {
    return core.mapM_(self, Function_1.identity, __trace);
}
exports.flattenM = flattenM;
/**
 * A more powerful version of `fold` that allows recovering from any kind of failure except interruptions.
 */
function foldCause_(self, f, g, __trace) {
    return fold_(sandbox(self), f, g, __trace);
}
exports.foldCause_ = foldCause_;
/**
 * A more powerful version of `fold` that allows recovering from any kind of failure except interruptions.
 *
 * @ets_data_first foldCause_
 */
function foldCause(f, g, __trace) {
    return (self) => fold_(sandbox(self), f, g, __trace);
}
exports.foldCause = foldCause;
/**
 * Returns a new effect that ignores the success or failure of this effect.
 */
function ignore(self, __trace) {
    return fold_(self, Function_1.constVoid, Function_1.constVoid, __trace);
}
exports.ignore = ignore;
/**
 * Returns whether this managed effect is a failure.
 */
function isFailure(self, __trace) {
    return fold_(self, () => true, () => false, __trace);
}
exports.isFailure = isFailure;
/**
 * Returns whether this managed effect is a success.
 */
function isSuccess(self, __trace) {
    return fold_(self, () => false, () => true, __trace);
}
exports.isSuccess = isSuccess;
/**
 * Depending on the environment execute this or the other effect
 *
 * @ets_data_first join_
 */
function join(that, __trace) {
    return (self) => join_(self, that, __trace);
}
exports.join = join;
/**
 * Depending on the environment execute this or the other effect
 */
function join_(self, that, __trace) {
    return (core.chain_((0, environment_1.environment)(), E.fold((r) => core.provideAll_(self, r), (r1) => core.provideAll_(that, r1)), __trace));
}
exports.join_ = join_;
/**
 * Depending on provided environment returns either this one or the other effect.
 *
 * @ets_data_first joinEither_
 */
function joinEither(that, __trace) {
    return (self) => joinEither_(self, that, __trace);
}
exports.joinEither = joinEither;
/**
 * Depending on provided environment returns either this one or the other effect.
 */
function joinEither_(self, that, __trace) {
    return (core.chain_((0, environment_1.environment)(), E.fold((r0) => core.provideAll_(core.map_(self, E.left), r0), (r1) => core.provideAll_(core.map_(that, E.right), r1)), __trace));
}
exports.joinEither_ = joinEither_;
/**
 * Join self selectively with C
 */
function identityLeft(__trace) {
    return (self) => joinEither_(self, (0, environment_1.environment)(), __trace);
}
exports.identityLeft = identityLeft;
/**
 * Lifts a synchronous side-effect into a `Managed[R, E, A]`,
 * translating any thrown exceptions into typed failed effects using onThrow.
 */
function tryCatch(f, onThrow, __trace) {
    return (0, fromEffect_1.fromEffect)(T.tryCatch(f, onThrow), __trace);
}
exports.tryCatch = tryCatch;
/**
 * Returns an effect whose success is mapped by the specified side effecting
 * `f` function, translating any thrown exceptions into typed failed effects.
 *
 * @ets_data_first mapTryCatch_
 */
function mapTryCatch(onThrow, f, __trace) {
    return (self) => mapTryCatch_(self, onThrow, f, __trace);
}
exports.mapTryCatch = mapTryCatch;
/**
 * Returns an effect whose success is mapped by the specified side effecting
 * `f` function, translating any thrown exceptions into typed failed effects.
 */
function mapTryCatch_(self, onThrow, f, __trace) {
    return (0, foldM_1.foldM_)(self, (e) => core.fail(e), (a) => tryCatch(() => f(a), onThrow), __trace);
}
exports.mapTryCatch_ = mapTryCatch_;
/**
 * Returns an effect whose success is mapped by the specified side effecting
 * `f` function, translating any thrown exceptions into typed failed effects.
 */
function mapEffect_(self, f, __trace) {
    return mapTryCatch_(self, Function_1.identity, f, __trace);
}
exports.mapEffect_ = mapEffect_;
/**
 * Returns an effect whose success is mapped by the specified side effecting
 * `f` function, translating any thrown exceptions into typed failed effects.
 *
 * @ets_data_first mapEffect_
 */
function mapEffect(f, __trace) {
    return (self) => mapEffect_(self, f, __trace);
}
exports.mapEffect = mapEffect;
/**
 * Preallocates the managed resource, resulting in a Managed that reserves
 * and acquires immediately and cannot fail. You should take care that you
 * are not interrupted between running preallocate and actually acquiring
 * the resource as you might leak otherwise.
 */
function preallocate(self, __trace) {
    return T.uninterruptibleMask(({ restore }) => (T.map_(T.bind_(T.bind_(T.bind_(T.do, "releaseMap", () => makeReleaseMap.makeReleaseMap), "tp", ({ releaseMap }) => T.result(restore(T.provideSome_(self.effect, (r) => Tp.tuple(r, releaseMap)), __trace))), "preallocated", ({ releaseMap, tp }) => Ex.foldM_(tp, (c) => (T.zipRight_(releaseAll.releaseAll(Ex.fail(c), T.sequential)(releaseMap), T.halt(c))), ({ tuple: [release, a] }) => T.succeed((0, managed_1.managedApply)(T.accessM(({ tuple: [_, releaseMap] }) => T.map_(add.add(release)(releaseMap), (_) => Tp.tuple(_, a))))))), ({ preallocated }) => preallocated)));
}
exports.preallocate = preallocate;
/**
 * Preallocates the managed resource inside an outer managed, resulting in a
 * Managed that reserves and acquires immediately and cannot fail.
 */
function preallocateManaged(self, __trace) {
    return (0, managed_1.managedApply)(T.map_(self.effect, ({ tuple: [release, a] }) => Tp.tuple(release, (0, managed_1.managedApply)(T.accessM(({ tuple: [_, releaseMap] }) => T.map_(add.add(release)(releaseMap), (_) => Tp.tuple(_, a))))), __trace));
}
exports.preallocateManaged = preallocateManaged;
/**
 * Provides a layer to the `Managed`, which translates it to another level.
 *
 * @ets_data_first provideLayer_
 */
function provideLayer(layer, __trace) {
    return (self) => provideLayer_(self, layer, __trace);
}
exports.provideLayer = provideLayer;
/**
 * Provides a layer to the `Managed`, which translates it to another level.
 */
function provideLayer_(self, layer, __trace) {
    return core.chain_(L.build(layer), (r) => core.provideAll_(self, r), __trace);
}
exports.provideLayer_ = provideLayer_;
/**
 * Splits the environment into two parts, providing one part using the
 * specified layer and leaving the remainder `R0`.
 */
function provideSomeLayer(layer, __trace) {
    return (self) => provideLayer_(self, layer["+++"](L.identity()), __trace);
}
exports.provideSomeLayer = provideSomeLayer;
/**
 * Keeps some of the errors, and terminates the fiber with the rest, using
 * the specified function to convert the `E` into a `Throwable`.
 *
 * @ets_data_first refineOrDieWith_
 */
function refineOrDieWith(pf, f, __trace) {
    return (self) => refineOrDieWith_(self, pf, f);
}
exports.refineOrDieWith = refineOrDieWith;
/**
 * Keeps some of the errors, and terminates the fiber with the rest, using
 * the specified function to convert the `E` into a `Throwable`.
 */
function refineOrDieWith_(self, pf, f, __trace) {
    return catchAll_(self, (e) => (O.fold_(pf(e), () => die(f(e), __trace), (e1) => core.fail(e1, __trace))));
}
exports.refineOrDieWith_ = refineOrDieWith_;
/**
 * Keeps some of the errors, and terminates the fiber with the rest
 *
 * @ets_data_first refineOrDie_
 */
function refineOrDie(pf, __trace) {
    return (self) => refineOrDie_(self, pf, __trace);
}
exports.refineOrDie = refineOrDie;
/**
 * Keeps some of the errors, and terminates the fiber with the rest
 */
function refineOrDie_(self, pf, __trace) {
    return refineOrDieWith_(self, pf, Function_1.identity, __trace);
}
exports.refineOrDie_ = refineOrDie_;
/**
 * Returns a managed that dies with the specified `unknown`. This method
 * can be used for terminating a fiber because a defect has been
 * detected in the code.
 */
function die(e, __trace) {
    return (0, fromEffect_1.fromEffect)(T.die(e, __trace));
}
exports.die = die;
/**
 * Returns a managed that dies with the specified `unknown`. This method
 * can be used for terminating a fiber because a defect has been
 * detected in the code.
 */
function dieWith(e, __trace) {
    return (0, fromEffect_1.fromEffect)(T.dieWith(e, __trace));
}
exports.dieWith = dieWith;
/**
 * Returns an effect that dies with a [[java.lang.RuntimeException]] having the
 * specified text message. This method can be used for terminating a fiber
 * because a defect has been detected in the code.
 */
function dieMessage(message, __trace) {
    return die(new Cause_1.RuntimeError(message), __trace);
}
exports.dieMessage = dieMessage;
/**
 * Continue with the returned computation if the `PartialFunction` matches,
 * translating the successful match into a failure, otherwise continue with
 * our held value.
 *
 * @ets_data_first rejectM_
 */
function rejectM(pf, __trace) {
    return (self) => rejectM_(self, pf, __trace);
}
exports.rejectM = rejectM;
/**
 * Continue with the returned computation if the `PartialFunction` matches,
 * translating the successful match into a failure, otherwise continue with
 * our held value.
 */
function rejectM_(self, pf, __trace) {
    return core.chain_(self, (a) => O.fold_(pf(a), () => (0, succeed_1.succeed)(a, __trace), (_) => core.chain_(_, (e1) => core.fail(e1), __trace)));
}
exports.rejectM_ = rejectM_;
/**
 * Fail with the returned value if the `PartialFunction` matches, otherwise
 * continue with our held value.
 *
 * @ets_data_first reject_
 */
function reject(pf, __trace) {
    return (self) => reject_(self, pf, __trace);
}
exports.reject = reject;
/**
 * Fail with the returned value if the `PartialFunction` matches, otherwise
 * continue with our held value.
 */
function reject_(self, pf, __trace) {
    return rejectM_(self, (x) => (O.map_(pf(x), core.fail)), __trace);
}
exports.reject_ = reject_;
/**
 * Runs all the finalizers associated with this scope. This is useful to
 * conceptually "close" a scope when composing multiple managed effects.
 * Note that this is only safe if the result of this managed effect is valid
 * outside its scope.
 */
function release(self, __trace) {
    return (0, fromEffect_1.fromEffect)(core.useNow(self), __trace);
}
exports.release = release;
/**
 * Returns an effect that retries this effect with the specified schedule when it fails, until
 * the schedule is done, then both the value produced by the schedule together with the last
 * error are passed to the specified recovery function.
 */
function retryOrElseEither_(self, policy, orElse, __trace) {
    return (0, managed_1.managedApply)(T.map_(T.accessM(({ tuple: [env, releaseMap] }) => T.provideAll_(T.retryOrElseEither_(T.provideAll_(self.effect, Tp.tuple(env, releaseMap)), policy, (e, o) => T.provideAll_(orElse(e, o).effect, Tp.tuple(env, releaseMap)), __trace), env)), E.fold(({ tuple: [f, a] }) => Tp.tuple(f, E.left(a)), ({ tuple: [f, a] }) => Tp.tuple(f, E.right(a)))));
}
exports.retryOrElseEither_ = retryOrElseEither_;
/**
 * Returns an effect that retries this effect with the specified schedule when it fails, until
 * the schedule is done, then both the value produced by the schedule together with the last
 * error are passed to the specified recovery function.
 *
 * @ets_data_first retryOrElseEither_
 */
function retryOrElseEither(policy, orElse, __trace) {
    return (self) => retryOrElseEither_(self, policy, orElse, __trace);
}
exports.retryOrElseEither = retryOrElseEither;
/**
 * Retries with the specified schedule, until it fails, and then both the
 * value produced by the schedule together with the last error are passed to
 * the recovery function.
 */
function retryOrElse_(self, policy, orElse, __trace) {
    return core.map_(retryOrElseEither_(self, policy, orElse, __trace), E.fold(Function_1.identity, Function_1.identity));
}
exports.retryOrElse_ = retryOrElse_;
/**
 * Retries with the specified schedule, until it fails, and then both the
 * value produced by the schedule together with the last error are passed to
 * the recovery function.
 *
 * @ets_data_first retryOrElse_
 */
function retryOrElse(policy, orElse, __trace) {
    return (self) => retryOrElse_(self, policy, orElse, __trace);
}
exports.retryOrElse = retryOrElse;
/**
 * Retries with the specified retry policy.
 * Retries are done following the failure of the original `io` (up to a fixed maximum with
 * `once` or `recurs` for example), so that that `io.retry(Schedule.once)` means
 * "execute `io` and in case of failure, try again once".
 */
function retry_(self, policy, __trace) {
    return retryOrElse_(self, policy, (e, _) => core.fail(e), __trace);
}
exports.retry_ = retry_;
/**
 * Retries with the specified retry policy.
 * Retries are done following the failure of the original `io` (up to a fixed maximum with
 * `once` or `recurs` for example), so that that `io.retry(Schedule.once)` means
 * "execute `io` and in case of failure, try again once".
 *
 * @ets_data_first retry_
 */
function retry(policy, __trace) {
    return (self) => retry_(self, policy, __trace);
}
exports.retry = retry;
/**
 * Returns an effect that semantically runs the effect on a fiber,
 * producing an `Exit` for the completion value of the fiber.
 */
function result(self, __trace) {
    return core.foldCauseM_(self, (x) => ((0, succeed_1.succeed)(Ex.halt(x))), (x) => ((0, succeed_1.succeed)(Ex.succeed(x))), __trace);
}
exports.result = result;
/**
 * Exposes the full cause of failure of this effect.
 */
function sandbox(self, __trace) {
    return (0, managed_1.managedApply)(T.sandbox(self.effect, __trace));
}
exports.sandbox = sandbox;
/**
 * The inverse operation to `sandbox`. Submerges the full cause of failure.
 */
function unsandbox(self) {
    return mapErrorCause_(self, C.flatten);
}
exports.unsandbox = unsandbox;
/**
 * Companion helper to `sandbox`. Allows recovery, and partial recovery, from
 * errors and defects alike.
 *
 * @ets_data_first sandboxWith_
 */
function sandboxWith(f) {
    return (self) => sandboxWith_(self, f);
}
exports.sandboxWith = sandboxWith;
/**
 * Companion helper to `sandbox`. Allows recovery, and partial recovery, from
 * errors and defects alike.
 */
function sandboxWith_(self, f) {
    return unsandbox(f(sandbox(self)));
}
exports.sandboxWith_ = sandboxWith_;
/**
 * Zips this effect with its environment
 */
function second(self) {
    return core.zip_((0, environment_1.environment)(), self);
}
exports.second = second;
/**
 * Converts an option on values into an option on errors.
 */
function some(self) {
    return (0, foldM_1.foldM_)(self, (x) => (core.fail(O.some(x))), O.fold(() => core.fail(O.none), succeed_1.succeed));
}
exports.some = some;
/**
 * Extracts the optional value, or returns the given 'orElse'.
 *
 * @ets_data_first someOrElse_
 */
function someOrElse(orElse) {
    return (self) => someOrElse_(self, orElse);
}
exports.someOrElse = someOrElse;
/**
 * Extracts the optional value, or returns the given 'orElse'.
 */
function someOrElse_(self, orElse) {
    return core.map_(self, O.getOrElse(orElse));
}
exports.someOrElse_ = someOrElse_;
/**
 * Extracts the optional value, or executes the effect 'orElse'.
 *
 * @ets_data_first someOrElseM_
 */
function someOrElseM(orElse) {
    return (self) => someOrElseM_(self, orElse);
}
exports.someOrElseM = someOrElseM;
/**
 * Extracts the optional value, or executes the effect 'orElse'.
 */
function someOrElseM_(self, orElse) {
    return core.chain_(self, O.fold(() => orElse, succeed_1.succeed));
}
exports.someOrElseM_ = someOrElseM_;
/**
 * Extracts the optional value, or fails with the given error 'e'.
 *
 * @ets_data_first someOrFail_
 */
function someOrFail(e) {
    return (self) => someOrFail_(self, e);
}
exports.someOrFail = someOrFail;
/**
 * Extracts the optional value, or fails with the given error 'e'.
 */
function someOrFail_(self, e) {
    return core.chain_(self, O.fold(() => core.fail(e()), succeed_1.succeed));
}
exports.someOrFail_ = someOrFail_;
/**
 * Extracts the optional value, or fails with a `NoSuchElementException`
 */
function someOrFailException(self) {
    return someOrFail_(self, () => new GlobalExceptions_1.NoSuchElementException());
}
exports.someOrFailException = someOrFailException;
/**
 * Returns an effect that effectfully peeks at the failure or success of the acquired resource.
 */
function tapBoth_(self, f, g) {
    return (0, foldM_1.foldM_)(self, (e) => core.chain_(f(e), () => core.fail(e)), (a) => core.map_(g(a), () => a));
}
exports.tapBoth_ = tapBoth_;
/**
 * Returns an effect that effectfully peeks at the failure or success of the acquired resource.
 *
 * @ets_data_first tapBoth_
 */
function tapBoth(f, g) {
    return (self) => tapBoth_(self, f, g);
}
exports.tapBoth = tapBoth;
/**
 * Returns an effect that effectually peeks at the cause of the failure of
 * the acquired resource.
 */
function tapCause_(self, f) {
    return catchAllCause_(self, (c) => core.chain_(f(c), () => (0, halt_1.halt)(c)));
}
exports.tapCause_ = tapCause_;
/**
 * Returns an effect that effectually peeks at the cause of the failure of
 * the acquired resource.
 *
 * @ets_data_first tapCause_
 */
function tapCause(f) {
    return (self) => tapCause_(self, f);
}
exports.tapCause = tapCause;
/**
 * Returns an effect that effectfully peeks at the failure of the acquired resource.
 */
function tapError_(self, f) {
    return tapBoth_(self, f, succeed_1.succeed);
}
exports.tapError_ = tapError_;
/**
 * Returns an effect that effectfully peeks at the failure of the acquired resource.
 *
 * @ets_data_first tapError_
 */
function tapError(f) {
    return (self) => tapError_(self, f);
}
exports.tapError = tapError;
/**
 * Like `tap`, but uses a function that returns a Effect value rather than a
 * Managed value.
 *
 * @ets_data_first tapM_
 */
function tapM(f) {
    return (self) => tapM_(self, f);
}
exports.tapM = tapM;
/**
 * Like `tap`, but uses a function that returns a Effect value rather than a
 * Managed value.
 */
function tapM_(self, f) {
    return core.mapM_(self, (a) => T.as_(f(a), a));
}
exports.tapM_ = tapM_;
/**
 * Returns a new effect that executes this one and times the acquisition of the resource.
 */
function timed(self) {
    return (0, managed_1.managedApply)(T.chain_(T.environment(), ({ tuple: [r, releaseMap] }) => T.provideSome_(T.map_(T.timed(T.provideAll_(self.effect, Tp.tuple(r, releaseMap))), ({ tuple: [duration, { tuple: [fin, a] }] }) => Tp.tuple(fin, Tp.tuple(duration, a))), (r) => r.get(0))));
}
exports.timed = timed;
/**
 * Returns an effect that will timeout this resource, returning `None` if the
 * timeout elapses before the resource was reserved and acquired.
 * If the reservation completes successfully (even after the timeout) the release action will be run on a new fiber.
 * `Some` will be returned if acquisition and reservation complete in time
 */
function timeout_(self, d) {
    return (0, managed_1.managedApply)(T.uninterruptibleMask(({ restore }) => T.gen(function* (_) {
        const env = yield* _(T.environment());
        const { tuple: [r, outerReleaseMap] } = env;
        const innerReleaseMap = yield* _(makeReleaseMap.makeReleaseMap);
        const earlyRelease = yield* _(add.add((exit) => releaseAll.releaseAll(exit, T.sequential)(innerReleaseMap))(outerReleaseMap));
        const raceResult = yield* _(restore(T.provideAll_(T.raceWith_(T.provideAll_(self.effect, Tp.tuple(r, innerReleaseMap)), T.as_(T.sleep(d), O.none), (result, sleeper) => T.zipRight_(F.interrupt(sleeper), T.done(Ex.map_(result, (tp) => E.right(tp.get(1))))), (_, resultFiber) => T.succeed(E.left(resultFiber))), r)));
        const a = yield* _(E.fold_(raceResult, (f) => T.as_(T.chain_(T.fiberId, (id) => T.forkDaemon(T.ensuring_(F.interrupt(f), releaseAll.releaseAll(Ex.interrupt(id), T.sequential)(innerReleaseMap)))), O.none), (v) => T.succeed(O.some(v))));
        return Tp.tuple(earlyRelease, a);
    })));
}
exports.timeout_ = timeout_;
/**
 * Returns an effect that will timeout this resource, returning `None` if the
 * timeout elapses before the resource was reserved and acquired.
 * If the reservation completes successfully (even after the timeout) the release action will be run on a new fiber.
 * `Some` will be returned if acquisition and reservation complete in time
 *
 * @ets_data_first timeout_
 */
function timeout(d) {
    return (self) => timeout_(self, d);
}
exports.timeout = timeout;
/**
 * Constructs a layer from this managed resource.
 *
 * @ets_data_first toLayer_
 */
function toLayer(tag) {
    return L.fromManaged(tag);
}
exports.toLayer = toLayer;
/**
 * Constructs a layer from this managed resource.
 */
function toLayer_(self, tag) {
    return toLayer(tag)(self);
}
exports.toLayer_ = toLayer_;
/**
 * Constructs a layer from this managed resource, which must return one or
 * more services.
 */
function toLayerMany(...tags) {
    return (self) => L.fromRawManaged(core.map_(self, (r) => {
        const env = {};
        for (const tag of tags) {
            env[tag.key] = tag.read(r);
        }
        return env;
    }));
}
exports.toLayerMany = toLayerMany;
/**
 * Return unit while running the effect
 */
function asUnit(self) {
    return as_(self, undefined);
}
exports.asUnit = asUnit;
/**
 * The moral equivalent of `if (!p) exp` when `p` has side-effects
 *
 * @ets_data_first unlessM_
 */
function unlessM(b) {
    return (self) => unlessM_(self, b);
}
exports.unlessM = unlessM;
/**
 * The moral equivalent of `if (!p) exp` when `p` has side-effects
 */
function unlessM_(self, b) {
    return core.chain_(b, (b) => (b ? exports.unit : asUnit(self)));
}
exports.unlessM_ = unlessM_;
/**
 * The moral equivalent of `if (!p) exp`
 *
 * @ets_data_first unless_
 */
function unless(b) {
    return unlessM(core.succeedWith(b));
}
exports.unless = unless;
/**
 * The moral equivalent of `if (!p) exp`
 */
function unless_(self, b) {
    return unless(b)(self);
}
exports.unless_ = unless_;
/**
 * Maps this effect to the specified constant while preserving the
 * effects of this effect.
 */
function as_(self, b) {
    return core.map_(self, () => b);
}
exports.as_ = as_;
/**
 * Maps this effect to the specified constant while preserving the
 * effects of this effect.
 *
 * @ets_data_first as_
 */
function as(b) {
    return (self) => as_(self, b);
}
exports.as = as;
/**
 * Maps the success value of this effect to an optional value.
 */
function asSome(self) {
    return core.map_(self, O.some);
}
exports.asSome = asSome;
/**
 * Maps the error value of this effect to an optional value.
 */
function asSomeError(self) {
    return mapError_(self, O.some);
}
exports.asSomeError = asSomeError;
/**
 * Maps the success value of this effect to a service.
 *
 * @ets_data_first asService_
 */
function asService(tag) {
    return (self) => asService_(self, tag);
}
exports.asService = asService;
/**
 * Maps the success value of this effect to a service.
 */
function asService_(self, tag) {
    return core.map_(self, tag.of);
}
exports.asService_ = asService_;
/**
 * Executes the this effect and then provides its output as an environment to the second effect
 */
function andThen_(self, that) {
    return core.chain_(self, (a) => core.provideAll_(that, a));
}
exports.andThen_ = andThen_;
/**
 * Executes the this effect and then provides its output as an environment to the second effect
 *
 * @ets_data_first andThen_
 */
function andThen(that) {
    return (self) => andThen_(self, that);
}
exports.andThen = andThen;
/**
 * Returns an effect whose failure and success channels have been mapped by
 * the specified pair of functions, `f` and `g`.
 *
 * @ets_data_first bimap_
 */
function bimap(f, g) {
    return (self) => bimap_(self, f, g);
}
exports.bimap = bimap;
/**
 * Returns an effect whose failure and success channels have been mapped by
 * the specified pair of functions, `f` and `g`.
 */
function bimap_(self, f, g) {
    return core.map_(mapError_(self, f), g);
}
exports.bimap_ = bimap_;
/**
 * Joins with environment passing self selectively on the right side
 */
function right() {
    return (self) => joinEither_((0, environment_1.environment)(), self);
}
exports.right = right;
/**
 * Joins with environment passing self selectively on the left side
 */
function left() {
    return (self) => joinEither_(self, (0, environment_1.environment)());
}
exports.left = left;
/**
 * Effectfully accesses the environment of the effect.
 */
function access(f, __trace) {
    return (0, fromEffect_1.fromEffect)(T.access(f), __trace);
}
exports.access = access;
/**
 * Effectfully accesses the environment of the effect.
 */
function accessManaged(f) {
    return core.chain_((0, environment_1.environment)(), f);
}
exports.accessManaged = accessManaged;
/**
 * Effectfully accesses the environment of the effect.
 */
function accessM(f) {
    return core.mapM_((0, environment_1.environment)(), f);
}
exports.accessM = accessM;
/**
 * Access a record of services with the required Service Entries
 */
function accessServicesM(s) {
    return (f) => accessManaged((r) => f(R.map_(s, (v) => r[v.key])));
}
exports.accessServicesM = accessServicesM;
/**
 * Access a tuple of services with the required Service Entries monadically
 */
function accessServicesTM(...s) {
    return (f) => accessManaged((r) => f(...A.map_(s, (v) => r[v.key])));
}
exports.accessServicesTM = accessServicesTM;
/**
 * Access a tuple of services with the required Service Entries
 */
function accessServicesT(...s) {
    return (f) => access((r) => f(...A.map_(s, (v) => r[v.key])));
}
exports.accessServicesT = accessServicesT;
/**
 * Access a record of services with the required Service Entries
 */
function accessServices(s) {
    return (f) => access((r) => f(R.map_(s, (v) => r[v.key])));
}
exports.accessServices = accessServices;
/**
 * Access a service with the required Service Entry
 */
function accessServiceM(s) {
    return (f) => accessManaged((r) => f(r[s.key]));
}
exports.accessServiceM = accessServiceM;
/**
 * Access a service with the required Service Entry
 */
function accessService(s) {
    return (f) => accessServiceM(s)((a) => (0, succeed_1.succeed)(f(a)));
}
exports.accessService = accessService;
/**
 * Accesses the specified service in the environment of the effect.
 */
function service(s) {
    return accessServiceM(s)((a) => (0, succeed_1.succeed)(a));
}
exports.service = service;
/**
 * Accesses the specified services in the environment of the effect.
 */
function services(...s) {
    return access((r) => s.map((tag) => tag.read(r)));
}
exports.services = services;
/**
 * Provides the service with the required Service Entry
 */
function provideServiceM(_) {
    return (f) => (ma) => accessManaged((r) => core.chain_(f, (t) => core.provideAll_(ma, (0, Has_1.mergeEnvironments)(_, r, t))));
}
exports.provideServiceM = provideServiceM;
/**
 * Provides the service with the required Service Entry
 */
function provideService(_) {
    return (f) => (ma) => provideServiceM(_)((0, succeed_1.succeed)(f))(ma);
}
exports.provideService = provideService;
/**
 * Replaces the service with the required Service Entry
 *
 * @ets_data_first replaceServiceM_
 */
function replaceServiceM(_, f) {
    return (ma) => accessServiceM(_)((t) => provideServiceM(_)(f(t))(ma));
}
exports.replaceServiceM = replaceServiceM;
/**
 * Replaces the service with the required Service Entry
 */
function replaceServiceM_(ma, _, f) {
    return accessServiceM(_)((t) => provideServiceM(_)(f(t))(ma));
}
exports.replaceServiceM_ = replaceServiceM_;
/**
 * Replaces the service with the required Service Entry
 *
 * @ets_data_first replaceService_
 */
function replaceService(_, f) {
    return (ma) => accessServiceM(_)((t) => provideServiceM(_)((0, succeed_1.succeed)(f(t)))(ma));
}
exports.replaceService = replaceService;
/**
 * Replaces the service with the required Service Entry
 */
function replaceService_(ma, _, f) {
    return accessServiceM(_)((t) => provideServiceM(_)((0, succeed_1.succeed)(f(t)))(ma));
}
exports.replaceService_ = replaceService_;
/**
 * The moral equivalent of `if (p) exp` when `p` has side-effects
 */
function whenM(b) {
    return unlessM(core.map_(b, (b) => !b));
}
exports.whenM = whenM;
/**
 * The moral equivalent of `if (p) exp`
 */
function when(b) {
    return unless(() => !b());
}
exports.when = when;
/**
 * A more powerful version of `withEarlyRelease` that allows specifying an
 * exit value in the event of early release.
 */
function withEarlyReleaseExit_(self, exit) {
    return (0, managed_1.managedApply)(T.map_(self.effect, (tp) => Tp.tuple(tp.get(0), Tp.tuple(T.uninterruptible(tp.get(0)(exit)), tp.get(1)))));
}
exports.withEarlyReleaseExit_ = withEarlyReleaseExit_;
/**
 * A more powerful version of `withEarlyRelease` that allows specifying an
 * exit value in the event of early release.
 *
 * @ets_data_first withEarlyReleaseExit_
 */
function withEarlyReleaseExit(exit) {
    return (self) => withEarlyReleaseExit_(self, exit);
}
exports.withEarlyReleaseExit = withEarlyReleaseExit;
/**
 * Returns an effect that succeeds with the `Fiber.Id` of the caller.
 */
exports.fiberId = (0, fromEffect_1.fromEffect)(T.fiberId);
/**
 * Modifies this `Managed` to provide a canceler that can be used to eagerly
 * execute the finalizer of this `Managed`. The canceler will run
 * uninterruptibly with an exit value indicating that the effect was
 * interrupted, and if completed will cause the regular finalizer to not run.
 */
function withEarlyRelease(self) {
    return core.chain_(exports.fiberId, (id) => withEarlyReleaseExit_(self, Ex.interrupt(id)));
}
exports.withEarlyRelease = withEarlyRelease;
/**
 * Sequentially zips this effect with the specified effect
 * returning the left side
 */
function zipLeft_(a, b) {
    return core.zipWith_(a, b, (a) => a);
}
exports.zipLeft_ = zipLeft_;
/**
 * Sequentially zips this effect with the specified effect
 * returning the left side
 *
 * @ets_data_first zipLeft_
 */
function zipLeft(b) {
    return (a) => zipLeft_(a, b);
}
exports.zipLeft = zipLeft;
/**
 * Parallelly zips this effect with the specified effect
 * returning the left side
 */
function zipLeftPar_(a, b) {
    return core.zipWithPar_(a, b, (a) => a);
}
exports.zipLeftPar_ = zipLeftPar_;
/**
 * Parallelly zips this effect with the specified effect
 * returning the left side
 *
 * @ets_data_first zipLeftPar_
 */
function zipLeftPar(b) {
    return (a) => zipLeftPar_(a, b);
}
exports.zipLeftPar = zipLeftPar;
/**
 * Sequentially zips this effect with the specified effect
 * returning the right side
 */
function zipRight_(a, b) {
    return core.zipWith_(a, b, (_, a) => a);
}
exports.zipRight_ = zipRight_;
/**
 * Sequentially zips this effect with the specified effect
 * returning the right side
 *
 * @ets_data_first zipRight_
 */
function zipRight(b) {
    return (a) => zipRight_(a, b);
}
exports.zipRight = zipRight;
/**
 * Parallelly zips this effect with the specified effect
 * returning the right side
 */
function zipRightPar_(a, b) {
    return core.zipWithPar_(a, b, (_, a) => a);
}
exports.zipRightPar_ = zipRightPar_;
/**
 * Parallelly zips this effect with the specified effect
 * returning the right side
 *
 * @ets_data_first zipRightPar_
 */
function zipRightPar(b) {
    return (a) => zipRightPar_(a, b);
}
exports.zipRightPar = zipRightPar;
/**
 * Parallely zips this effects
 */
function zipPar_(a, b) {
    return core.zipWithPar_(a, b, (a, b) => [a, b]);
}
exports.zipPar_ = zipPar_;
/**
 * Parallely zips this effects
 *
 * @ets_data_first zipPar_
 */
function zipPar(b) {
    return (a) => zipPar_(a, b);
}
exports.zipPar = zipPar;
/**
 * Creates new `Managed` from a `Effect` value that uses a `ReleaseMap` and returns
 * a resource and a finalizer.
 *
 * The correct usage of this constructor consists of:
 * - Properly registering a finalizer in the ReleaseMap as part of the `Effect` value;
 * - Managing interruption safety - take care to use `uninterruptible` or
 *   `uninterruptibleMask` to verify that the finalizer is registered in the
 *   `ReleaseMap` after acquiring the value;
 * - Returning the finalizer returned from `ReleaseMap#add`. This is important
 *   to prevent double-finalization.
 */
function create(effect) {
    return (0, managed_1.managedApply)(effect);
}
exports.create = create;
/**
 * Evaluate the predicate,
 * return the given A as success if predicate returns true, and the given E as error otherwise
 */
function cond_(pred, result, error) {
    return pred ? (0, succeed_1.succeed)(result()) : core.fail(error());
}
exports.cond_ = cond_;
/**
 * Evaluate the predicate,
 * return the given A as success if predicate returns true, and the given E as error otherwise
 *
 * @ets_data_first cond_
 */
function cond(result, error) {
    return (pred) => cond_(pred, result, error);
}
exports.cond = cond;
/**
 * Applies the function `f` to each element of the `Iterable[A]` and runs
 * produced effects in parallel, discarding the results.
 *
 * For a sequential version of this method, see `forEachUnit_`.
 */
function forEachUnitPar_(as, f, __trace) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel, __trace), (parallelReleaseMap) => {
        const makeInnerMap = T.provideSome_(T.map_(core.makeManagedReleaseMap(T.sequential).effect, (_) => _.get(1)), (r) => Tp.tuple(r, parallelReleaseMap));
        return T.forEachUnitPar_(as, (a) => T.chain_(makeInnerMap, (innerMap) => T.provideSome_(T.map_(f(a).effect, (_) => _.get(1)), (r) => Tp.tuple(r, innerMap))));
    });
}
exports.forEachUnitPar_ = forEachUnitPar_;
/**
 * Applies the function `f` to each element of the `Iterable[A]` and runs
 * produced effects in parallel, discarding the results.
 *
 * For a sequential version of this method, see `forEachUnit_`.
 *
 * @ets_data_first forEachUnitPar_
 */
function forEachUnitPar(f, __trace) {
    return (as) => forEachUnitPar_(as, f, __trace);
}
exports.forEachUnitPar = forEachUnitPar;
/**
 * Applies the function `f` to each element of the `Iterable[A]` and runs
 * produced effects in parallel, discarding the results.
 *
 * For a sequential version of this method, see `forEachUnit_`.
 */
function forEachUnitParN_(as, n, f, __trace) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel, __trace), (parallelReleaseMap) => {
        const makeInnerMap = T.provideSome_(T.map_(core.makeManagedReleaseMap(T.sequential).effect, (_) => _.get(1)), (r) => Tp.tuple(r, parallelReleaseMap));
        return T.forEachUnitParN_(as, n, (a) => T.chain_(makeInnerMap, (innerMap) => T.provideSome_(T.map_(f(a).effect, (_) => _.get(1)), (r) => Tp.tuple(r, innerMap))));
    });
}
exports.forEachUnitParN_ = forEachUnitParN_;
/**
 * Applies the function `f` to each element of the `Iterable[A]` and runs
 * produced effects in parallel, discarding the results.
 *
 * For a sequential version of this method, see `forEachUnit_`.
 *
 * @ets_data_first forEachUnitParN_
 */
function forEachUnitParN(n, f) {
    return (as) => forEachUnitParN_(as, n, f);
}
exports.forEachUnitParN = forEachUnitParN;
/**
 * Evaluate each effect in the structure from left to right, collecting the
 * the successful values and discarding the empty cases. For a parallel version, see `collectPar`.
 *
 * @ets_data_first collect_
 */
function collect(f) {
    return (self) => collect_(self, f);
}
exports.collect = collect;
/**
 * Evaluate each effect in the structure from left to right, collecting the
 * the successful values and discarding the empty cases. For a parallel version, see `collectPar`.
 */
function collect_(self, f) {
    return core.map_(forEach.forEach_(self, (a) => optional(f(a))), Chunk.compact);
}
exports.collect_ = collect_;
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * @ets_data_first collectPar_
 */
function collectPar(f) {
    return (self) => collectPar_(self, f);
}
exports.collectPar = collectPar;
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 */
function collectPar_(self, f) {
    return core.map_(forEach.forEachPar_(self, (a) => optional(f(a))), Chunk.compact);
}
exports.collectPar_ = collectPar_;
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * Unlike `collectPar`, this method will use at most up to `n` fibers.
 */
function collectParN_(self, n, f) {
    return core.map_(forEach.forEachParN_(self, n, (a) => optional(f(a))), Chunk.compact);
}
exports.collectParN_ = collectParN_;
/**
 * Evaluate each effect in the structure in parallel, collecting the
 * the successful values and discarding the empty cases.
 *
 * Unlike `collectPar`, this method will use at most up to `n` fibers.
 *
 * @ets_data_first collectParN_
 */
function collectParN(n, f) {
    return (self) => collectParN_(self, n, f);
}
exports.collectParN = collectParN;
/**
 * Evaluate each effect in the structure from left to right, and collect the
 * results. For a parallel version, see `collectAllPar`.
 */
function collectAll(as, __trace) {
    return forEach.forEach_(as, Function_1.identity, __trace);
}
exports.collectAll = collectAll;
/**
 * Evaluate each effect in the structure in parallel, and collect the
 * results. For a sequential version, see `collectAll`.
 */
function collectAllPar(as, __trace) {
    return forEach.forEachPar_(as, Function_1.identity, __trace);
}
exports.collectAllPar = collectAllPar;
/**
 * Evaluate each effect in the structure in parallel, and collect the
 * results. For a sequential version, see `collectAll`.
 *
 * Unlike `collectAllPar`, this method will use at most `n` fibers.
 *
 * @ets_data_first collectAllParN_
 */
function collectAllParN(n, __trace) {
    return (as) => forEach.forEachParN_(as, n, Function_1.identity, __trace);
}
exports.collectAllParN = collectAllParN;
/**
 * Evaluate each effect in the structure in parallel, and collect the
 * results. For a sequential version, see `collectAll`.
 *
 * Unlike `collectAllPar`, this method will use at most `n` fibers.
 */
function collectAllParN_(as, n, __trace) {
    return forEach.forEachParN_(as, n, Function_1.identity, __trace);
}
exports.collectAllParN_ = collectAllParN_;
/**
 * Evaluate each effect in the structure from left to right, and discard the
 * results. For a parallel version, see `collectAllUnitPar`.
 */
function collectAllUnit(as, __trace) {
    return forEach.forEachUnit_(as, Function_1.identity, __trace);
}
exports.collectAllUnit = collectAllUnit;
/**
 * Evaluate each effect in the structure in parallel, and discard the
 * results. For a sequential version, see `collectAllUnit`.
 */
function collectAllUnitPar(as, __trace) {
    return forEachUnitPar_(as, Function_1.identity, __trace);
}
exports.collectAllUnitPar = collectAllUnitPar;
/**
 * Evaluate each effect in the structure in parallel, and discard the
 * results. For a sequential version, see `collectAllUnit`.
 *
 * Unlike `collectAllUnitPar`, this method will use at most `n` fibers.
 *
 * @ets_data_first collectAllUnitParN_
 */
function collectAllUnitParN(n, __trace) {
    return (as) => forEachUnitParN_(as, n, Function_1.identity, __trace);
}
exports.collectAllUnitParN = collectAllUnitParN;
/**
 * Evaluate each effect in the structure in parallel, and discard the
 * results. For a sequential version, see `collectAllUnit`.
 *
 * Unlike `collectAllUnitPar`, this method will use at most `n` fibers.
 */
function collectAllUnitParN_(as, n, __trace) {
    return forEachUnitParN_(as, n, Function_1.identity, __trace);
}
exports.collectAllUnitParN_ = collectAllUnitParN_;
/**
 * Evaluate each effect in the structure with `collectAll`, and collect
 * the results with given partial function.
 */
function collectAllWith_(as, pf, __trace) {
    return core.map_(collectAll(as, __trace), Chunk.filterMap(pf));
}
exports.collectAllWith_ = collectAllWith_;
/**
 * Evaluate each effect in the structure with `collectAll`, and collect
 * the results with given partial function.
 *
 * @ets_data_first collectAllWith_
 */
function collectAllWith(pf, __trace) {
    return (as) => collectAllWith_(as, pf, __trace);
}
exports.collectAllWith = collectAllWith;
/**
 * Evaluate each effect in the structure with `collectAll`, and collect
 * the results with given partial function.
 */
function collectAllWithPar_(as, pf, __trace) {
    return core.map_(collectAllPar(as, __trace), Chunk.filterMap(pf));
}
exports.collectAllWithPar_ = collectAllWithPar_;
/**
 * Evaluate each effect in the structure with `collectAll`, and collect
 * the results with given partial function.
 *
 * @ets_data_first collectAllWithPar_
 */
function collectAllWithPar(pf, __trace) {
    return (as) => collectAllWithPar_(as, pf, __trace);
}
exports.collectAllWithPar = collectAllWithPar;
/**
 * Evaluate each effect in the structure with `collectAllPar`, and collect
 * the results with given partial function.
 *
 * Unlike `collectAllWithPar`, this method will use at most up to `n` fibers.
 */
function collectAllWithParN_(as, n, pf, __trace) {
    return core.map_(collectAllParN_(as, n, __trace), Chunk.filterMap(pf));
}
exports.collectAllWithParN_ = collectAllWithParN_;
/**
 * Evaluate each effect in the structure with `collectAllPar`, and collect
 * the results with given partial function.
 *
 * Unlike `collectAllWithPar`, this method will use at most up to `n` fibers.
 *
 * @ets_data_first collectAllWithParN_
 */
function collectAllWithParN(n, pf, __trace) {
    return (as) => collectAllWithParN_(as, n, pf, __trace);
}
exports.collectAllWithParN = collectAllWithParN;
/**
 * Evaluate and run each effect in the structure and collect discarding failed ones.
 */
function collectAllSuccesses(as, __trace) {
    return collectAllWith_(I.map_(as, (x) => result(x)), (e) => (e._tag === "Success" ? O.some(e.value) : O.none), __trace);
}
exports.collectAllSuccesses = collectAllSuccesses;
/**
 * Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
 */
function collectAllSuccessesPar(as, __trace) {
    return collectAllWithPar_(I.map_(as, (x) => result(x)), (e) => (e._tag === "Success" ? O.some(e.value) : O.none), __trace);
}
exports.collectAllSuccessesPar = collectAllSuccessesPar;
/**
 * Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
 *
 * Unlike `collectAllSuccessesPar`, this method will use at most up to `n` fibers.
 *
 * @ets_data_first collectAllSuccessesParN_
 */
function collectAllSuccessesParN(n, __trace) {
    return (as) => collectAllSuccessesParN_(as, n, __trace);
}
exports.collectAllSuccessesParN = collectAllSuccessesParN;
/**
 * Evaluate and run each effect in the structure in parallel, and collect discarding failed ones.
 *
 * Unlike `collectAllSuccessesPar`, this method will use at most up to `n` fibers.
 */
function collectAllSuccessesParN_(as, n, __trace) {
    return collectAllWithParN_(I.map_(as, (x) => result(x)), n, (e) => (e._tag === "Success" ? O.some(e.value) : O.none), __trace);
}
exports.collectAllSuccessesParN_ = collectAllSuccessesParN_;
/**
 * Creates an effect that only executes the provided function as its
 * release action.
 */
function finalizerExit(f, __trace) {
    return (0, makeExit_1.makeExit_)(T.unit, (_, e) => f(e), __trace);
}
exports.finalizerExit = finalizerExit;
/**
 * Creates an effect that only executes the provided finalizer as its
 * release action.
 */
function finalizer(f, __trace) {
    return finalizerExit(() => f, __trace);
}
exports.finalizer = finalizer;
/**
 * Folds an Iterable[A] using an effectual function f, working sequentially from left to right.
 */
function reduce_(i, zero, f, __trace) {
    return (0, suspend_1.suspend)(() => A.reduce_(Array.from(i), (0, succeed_1.succeed)(zero), (acc, el) => core.chain_(acc, (a) => f(a, el))), __trace);
}
exports.reduce_ = reduce_;
/**
 * Folds an Iterable[A] using an effectual function f, working sequentially from left to right.
 *
 * @ets_data_first reduce_
 */
function reduce(zero, f, __trace) {
    return (i) => reduce_(i, zero, f, __trace);
}
exports.reduce = reduce;
/**
 * Folds an Iterable[A] using an effectual function f, working sequentially from left to right.
 */
function reduceRight_(i, zero, f, __trace) {
    return (0, suspend_1.suspend)(() => A.reduceRight_(Array.from(i), (0, succeed_1.succeed)(zero), (el, acc) => core.chain_(acc, (a) => f(el, a))), __trace);
}
exports.reduceRight_ = reduceRight_;
/**
 * Folds an Iterable[A] using an effectual function f, working sequentially from left to right.
 *
 * @ets_data_first reduceRight_
 */
function reduceRight(zero, f) {
    return (i) => reduceRight_(i, zero, f);
}
exports.reduceRight = reduceRight;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working sequentially.
 */
function reduceAll_(as, f) {
    return A.reduce_(NA.tail(as), NA.head(as), (acc, a) => core.zipWith_(acc, a, f));
}
exports.reduceAll_ = reduceAll_;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working sequentially.
 *
 * @ets_data_first reduceAll_
 */
function reduceAll(f) {
    return (as) => reduceAll_(as, f);
}
exports.reduceAll = reduceAll;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working in parallel.
 */
function reduceAllPar_(as, f) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel), (parallelReleaseMap) => T.provideSome_(T.reduceAllPar_(NA.map_(as, (_) => T.map_(_.effect, (_) => _.get(1))), f), (r) => Tp.tuple(r, parallelReleaseMap)));
}
exports.reduceAllPar_ = reduceAllPar_;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working in parallel.
 *
 * @ets_data_first reduceAllPar_
 */
function reduceAllPar(f) {
    return (as) => reduceAllPar_(as, f);
}
exports.reduceAllPar = reduceAllPar;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working in up to `n` fibers in parallel.
 */
function reduceAllParN_(as, n, f) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel), (parallelReleaseMap) => T.provideSome_(T.reduceAllParN_(NA.map_(as, (_) => T.map_(_.effect, (_) => _.get(1))), n, f), (r) => Tp.tuple(r, parallelReleaseMap)));
}
exports.reduceAllParN_ = reduceAllParN_;
/**
 * Reduces an `Iterable[IO]` to a single `IO`, working in up to `n` fibers in parallel.
 *
 * @ets_data_first reduceAllParN_
 */
function reduceAllParN(n, f) {
    return (as) => reduceAllParN_(as, n, f);
}
exports.reduceAllParN = reduceAllParN;
/**
 * Merges an `Iterable[IO]` to a single IO, working sequentially.
 *
 * @ets_data_first mergeAll_
 */
function mergeAll(zero, f) {
    return (as) => mergeAll_(as, zero, f);
}
exports.mergeAll = mergeAll;
/**
 * Merges an `Iterable[IO]` to a single IO, working sequentially.
 */
function mergeAll_(as, zero, f) {
    return I.reduce_(as, (0, succeed_1.succeed)(zero), (b, a) => core.zipWith_(b, a, f));
}
exports.mergeAll_ = mergeAll_;
/**
 * Merges an `Iterable[IO]` to a single IO, working in parallel.
 *
 * Due to the parallel nature of this combinator, `f` must be both:
 * - commutative: `f(a, b) == f(b, a)`
 * - associative: `f(a, f(b, c)) == f(f(a, b), c)`
 *
 * It's unsafe to execute side effects inside `f`, as `f` may be executed
 * more than once for some of `in` elements during effect execution.
 *
 * @ets_data_first mergeAllPar_
 */
function mergeAllPar(zero, f) {
    return (as) => mergeAllPar_(as, zero, f);
}
exports.mergeAllPar = mergeAllPar;
/**
 * Merges an `Iterable[IO]` to a single IO, working in parallel.
 *
 * Due to the parallel nature of this combinator, `f` must be both:
 * - commutative: `f(a, b) == f(b, a)`
 * - associative: `f(a, f(b, c)) == f(f(a, b), c)`
 *
 * It's unsafe to execute side effects inside `f`, as `f` may be executed
 * more than once for some of `in` elements during effect execution.
 */
function mergeAllPar_(as, zero, f) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel), (parallelReleaseMap) => T.provideSome_(T.mergeAllPar_(I.map_(as, (_) => T.map_(_.effect, (_) => _.get(1))), zero, f), (r) => Tp.tuple(r, parallelReleaseMap)));
}
exports.mergeAllPar_ = mergeAllPar_;
/**
 * Merges an `Iterable[IO]` to a single IO, working in with up to `n` fibers in parallel.
 *
 * Due to the parallel nature of this combinator, `f` must be both:
 * - commutative: `f(a, b) == f(b, a)`
 * - associative: `f(a, f(b, c)) == f(f(a, b), c)`
 *
 * It's unsafe to execute side effects inside `f`, as `f` may be executed
 * more than once for some of `in` elements during effect execution.
 *
 * @ets_data_first mergeAllParN_
 */
function mergeAllParN(n, zero, f) {
    return (as) => mergeAllParN_(as, n, zero, f);
}
exports.mergeAllParN = mergeAllParN;
/**
 * Merges an `Iterable[IO]` to a single IO, working in with up to `n` fibers in parallel.
 *
 * Due to the parallel nature of this combinator, `f` must be both:
 * - commutative: `f(a, b) == f(b, a)`
 * - associative: `f(a, f(b, c)) == f(f(a, b), c)`
 *
 * It's unsafe to execute side effects inside `f`, as `f` may be executed
 * more than once for some of `in` elements during effect execution.
 */
function mergeAllParN_(as, n, zero, f) {
    return core.mapM_(core.makeManagedReleaseMap(T.parallel), (parallelReleaseMap) => T.provideSome_(T.mergeAllParN_(I.map_(as, (_) => T.map_(_.effect, (_) => _.get(1))), n, zero, f), (r) => Tp.tuple(r, parallelReleaseMap)));
}
exports.mergeAllParN_ = mergeAllParN_;
/**
 * Creates a scope in which resources can be safely allocated into together with a release action.
 */
exports.scope = core.map_(releaseMap_1.releaseMap, (finalizers) => (ma) => T.chain_(T.environment(), (r) => T.provideAll_(ma.effect, Tp.tuple(r, finalizers))));
/**
 * Locally installs a supervisor and an effect that succeeds with all the
 * children that have been forked in the returned effect.
 */
function withChildren(get) {
    return unwrap(T.map_(Supervisor_1.track, (supervisor) => (0, managed_1.managedApply)(T.supervised_(get(T.chain_(supervisor.value, (children) => T.map_(T.descriptor, (d) => SS.filter_(children, (_) => _.id !== d.id)))).effect, supervisor))));
}
exports.withChildren = withChildren;
/**
 * Unwraps a `Managed` that is inside an `Effect`.
 */
function unwrap(fa) {
    return flatten((0, fromEffect_1.fromEffect)(fa));
}
exports.unwrap = unwrap;
/**
 * Creates a `Managed` from an `AutoCloseable` resource. The resource's `close`
 * method will be used as the release action.
 */
function fromAutoClosable(fa) {
    return core.make_(fa, (a) => T.succeedWith(() => a.close()));
}
exports.fromAutoClosable = fromAutoClosable;
/**
 * Creates a `Managed` from an `AutoCloseable` resource. The resource's `close`
 * method will be used as the release action.
 */
function fromAutoClosableM(fa) {
    return core.make_(fa, (a) => a.close);
}
exports.fromAutoClosableM = fromAutoClosableM;
/**
 * Returns an effect that is interrupted as if by the fiber calling this
 * method.
 */
exports.interrupt = core.chain_((0, fromEffect_1.fromEffect)(T.descriptor), (d) => interruptAs(d.id));
/**
 * Returns an effect that is interrupted as if by the specified fiber.
 */
function interruptAs(id) {
    return (0, halt_1.halt)(C.interrupt(id));
}
exports.interruptAs = interruptAs;
/**
 * Low level expose internal trace pusher
 */
function exposeTracer(f) {
    return (0, managed_1.managedApply)(new primitives_1.ITracer((tracer) => f(tracer).effect));
}
exports.exposeTracer = exposeTracer;
//# sourceMappingURL=api.js.map