"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;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.catchAllCause = exports.catchAllCause_ = exports.readOrFail = exports.succeedWith = exports.fromEffect = exports.suspend = exports.chain = exports.chain_ = exports.provideAll = exports.provideAll_ = exports.acquireReleaseOutExitWith = exports.acquireReleaseOutExitWith_ = exports.embedInput = exports.embedInput_ = exports.foldCauseChannel = exports.foldCauseChannel_ = exports.concatAllWith = exports.concatAllWith_ = exports.concatMapWith = exports.concatMapWith_ = exports.ensuringWith = exports.ensuringWith_ = exports.write = exports.writeWith = exports.dieWith = exports.die = exports.fail = exports.failWith = exports.failCause = exports.failCauseWith = exports.end = exports.endWith = exports.readWithCause = exports.pipeTo = exports.pipeTo_ = exports.makeSingleProducerAsyncInput = void 0;
// ets_tracing: off
require("../../../Operator");
const Cause = __importStar(require("../../../Cause"));
const Function_1 = require("../../../Function");
const P = __importStar(require("./_internal/primitives"));
var producer_1 = require("./_internal/producer");
Object.defineProperty(exports, "makeSingleProducerAsyncInput", { enumerable: true, get: function () { return producer_1.makeSingleProducerAsyncInput; } });
__exportStar(require("./_internal/primitives"), exports);
/**
 * Pipe the output of a channel into the input of another
 */
function pipeTo_(left, right) {
    return new P.PipeTo(() => left, () => right);
}
exports.pipeTo_ = pipeTo_;
/**
 * Pipe the output of a channel into the input of another
 *
 * @ets_data_first pipeTo_
 */
function pipeTo(right) {
    return (left) => pipeTo_(left, right);
}
exports.pipeTo = pipeTo;
/**
 * Reads an input and continue exposing both full error cause and completion
 */
function readWithCause(inp, halt, done) {
    return new P.Read(inp, new P.ContinuationK(done, halt));
}
exports.readWithCause = readWithCause;
/**
 * End a channel with the specified result
 */
function endWith(result) {
    return new P.Done(result);
}
exports.endWith = endWith;
/**
 * End a channel with the specified result
 */
function end(result) {
    return new P.Done(() => result);
}
exports.end = end;
/**
 * Halt a channel with the specified cause
 */
function failCauseWith(result) {
    return new P.Halt(result);
}
exports.failCauseWith = failCauseWith;
/**
 * Halt a channel with the specified cause
 */
function failCause(result) {
    return new P.Halt(() => result);
}
exports.failCause = failCause;
/**
 * Halt a channel with the specified error
 */
function failWith(error) {
    return new P.Halt(() => Cause.fail(error()));
}
exports.failWith = failWith;
/**
 * Halt a channel with the specified error
 */
function fail(error) {
    return new P.Halt(() => Cause.fail(error));
}
exports.fail = fail;
/**
 * Halt a channel with the specified exception
 */
function die(defect) {
    return new P.Halt(() => Cause.die(defect));
}
exports.die = die;
/**
 * Halt a channel with the specified exception
 */
function dieWith(defect) {
    return new P.Halt(() => Cause.die(defect()));
}
exports.dieWith = dieWith;
/**
 * Writes an output to the channel
 */
function writeWith(out) {
    return new P.Emit(out);
}
exports.writeWith = writeWith;
/**
 * Writes an output to the channel
 */
function write(out) {
    return new P.Emit(() => out);
}
exports.write = write;
/**
 * Returns a new channel with an attached finalizer. The finalizer is guaranteed to be executed
 * so long as the channel begins execution (and regardless of whether or not it completes).
 */
function ensuringWith_(channel, finalizer) {
    return new P.Ensuring(channel, finalizer);
}
exports.ensuringWith_ = ensuringWith_;
/**
 * Returns a new channel with an attached finalizer. The finalizer is guaranteed to be executed
 * so long as the channel begins execution (and regardless of whether or not it completes).
 *
 * @ets_data_first ensuringWith_
 */
function ensuringWith(finalizer) {
    return (channel) => ensuringWith_(channel, finalizer);
}
exports.ensuringWith = ensuringWith;
/**
 * Returns a new channel whose outputs are fed to the specified factory function, which creates
 * new channels in response. These new channels are sequentially concatenated together, and all
 * their outputs appear as outputs of the newly returned channel. The provided merging function
 * is used to merge the terminal values of all channels into the single terminal value of the
 * returned channel.
 */
function concatMapWith_(self, f, g, h) {
    return new P.ConcatAll(g, h, self, f);
}
exports.concatMapWith_ = concatMapWith_;
/**
 * Returns a new channel whose outputs are fed to the specified factory function, which creates
 * new channels in response. These new channels are sequentially concatenated together, and all
 * their outputs appear as outputs of the newly returned channel. The provided merging function
 * is used to merge the terminal values of all channels into the single terminal value of the
 * returned channel.
 *
 * @ets_data_first concatMapWith_
 */
function concatMapWith(f, g, h) {
    return (self) => concatMapWith_(self, f, g, h);
}
exports.concatMapWith = concatMapWith;
/**
 * Concat sequentially a channel of channels
 */
function concatAllWith_(channels, f, g) {
    return new P.ConcatAll(f, g, channels, Function_1.identity);
}
exports.concatAllWith_ = concatAllWith_;
/**
 * Concat sequentially a channel of channels
 *
 * @ets_data_first concatAllWith_
 */
function concatAllWith(f, g) {
    return (channels) => concatAllWith_(channels, f, g);
}
exports.concatAllWith = concatAllWith;
/**
 * Fold the channel exposing success and full error cause
 */
function foldCauseChannel_(self, onErr, onSucc) {
    return new P.Fold(self, new P.ContinuationK(onSucc, onErr));
}
exports.foldCauseChannel_ = foldCauseChannel_;
/**
 * Fold the channel exposing success and full error cause
 *
 * @ets_data_first foldCauseChannel_
 */
function foldCauseChannel(onErr, onSucc) {
    return (self) => foldCauseChannel_(self, onErr, onSucc);
}
exports.foldCauseChannel = foldCauseChannel;
/**
 * Embed inputs from continuos pulling of a producer
 */
function embedInput_(self, input) {
    return new P.Bridge(input, self);
}
exports.embedInput_ = embedInput_;
/**
 * Embed inputs from continuos pulling of a producer
 *
 * @ets_data_first embedInput_
 */
function embedInput(input) {
    return (self) => embedInput_(self, input);
}
exports.embedInput = embedInput;
/**
 * Construct a resource Channel with Acquire / Release
 */
function acquireReleaseOutExitWith_(self, release) {
    return new P.BracketOut(self, release);
}
exports.acquireReleaseOutExitWith_ = acquireReleaseOutExitWith_;
/**
 * Construct a resource Channel with Acquire / Release
 *
 * @ets_data_first acquireReleaseOutExitWith_
 */
function acquireReleaseOutExitWith(release) {
    return (self) => acquireReleaseOutExitWith_(self, release);
}
exports.acquireReleaseOutExitWith = acquireReleaseOutExitWith;
/**
 * Provides the channel with its required environment, which eliminates
 * its dependency on `Env`.
 */
function provideAll_(self, env) {
    return new P.Provide(env, self);
}
exports.provideAll_ = provideAll_;
/**
 * Provides the channel with its required environment, which eliminates
 * its dependency on `Env`.
 *
 * @ets_data_first provideAll_
 */
function provideAll(env) {
    return (self) => provideAll_(self, env);
}
exports.provideAll = provideAll;
/**
 * Returns a new channel, which sequentially combines this channel, together with the provided
 * factory function, which creates a second channel based on the terminal value of this channel.
 * The result is a channel that will first perform the functions of this channel, before
 * performing the functions of the created channel (including yielding its terminal value).
 */
function chain_(self, f) {
    return new P.Fold(self, new P.ContinuationK(f, failCause));
}
exports.chain_ = chain_;
/**
 * Returns a new channel, which sequentially combines this channel, together with the provided
 * factory function, which creates a second channel based on the terminal value of this channel.
 * The result is a channel that will first perform the functions of this channel, before
 * performing the functions of the created channel (including yielding its terminal value).
 *
 * @ets_data_first chain_
 */
function chain(f) {
    return (self) => chain_(self, f);
}
exports.chain = chain;
function suspend(effect) {
    return new P.EffectSuspendTotal(effect);
}
exports.suspend = suspend;
/**
 * Use an effect to end a channel
 */
function fromEffect(self) {
    return new P.Effect(self);
}
exports.fromEffect = fromEffect;
function succeedWith(effect) {
    return new P.EffectTotal(effect);
}
exports.succeedWith = succeedWith;
function readOrFail(e) {
    return new P.Read((in_) => end(in_), new P.ContinuationK((_) => fail(e), (_) => fail(e)));
}
exports.readOrFail = readOrFail;
/**
 * Returns a new channel that is the same as this one, except if this channel errors for any
 * typed error, then the returned channel will switch over to using the fallback channel returned
 * by the specified error handler.
 */
function catchAllCause_(self, f) {
    return new P.Fold(self, new P.ContinuationK((_) => end(_), f));
}
exports.catchAllCause_ = catchAllCause_;
/**
 * Returns a new channel that is the same as this one, except if this channel errors for any
 * typed error, then the returned channel will switch over to using the fallback channel returned
 * by the specified error handler.
 *
 * @ets_data_first catchAllCause_
 */
function catchAllCause(f) {
    return (self) => catchAllCause_(self, f);
}
exports.catchAllCause = catchAllCause;
//# sourceMappingURL=core.js.map