"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.left = exports.leftOrFailException = exports.leftOrFail = exports.leftOrFail_ = void 0;
// ets_tracing: off
const E = __importStar(require("../Either"));
const GlobalExceptions_1 = require("../GlobalExceptions");
const O = __importStar(require("../Option"));
const core_1 = require("./core");
const fail_1 = require("./fail");
const foldM_1 = require("./foldM");
/**
 * Returns a successful effect if the value is `Left`, or fails with the error e.
 */
function leftOrFail_(self, orFail, __trace) {
    return (0, core_1.chain_)(self, E.fold(core_1.succeed, (x) => (0, fail_1.failWith)(() => orFail(x))), __trace);
}
exports.leftOrFail_ = leftOrFail_;
/**
 * Returns a successful effect if the value is `Left`, or fails with the error e.
 *
 * @ets_data_first leftOrFail_
 */
function leftOrFail(orFail, __trace) {
    return (self) => leftOrFail_(self, orFail, __trace);
}
exports.leftOrFail = leftOrFail;
/**
 * Returns a successful effect if the value is `Left`, or fails with a `NoSuchElementException`.
 */
function leftOrFailException(self, __trace) {
    return leftOrFail_(self, () => new GlobalExceptions_1.NoSuchElementException(), __trace);
}
exports.leftOrFailException = leftOrFailException;
/**
 * Returns a successful effect if the value is `Left`, or fails with the error `None`.
 */
function left(self) {
    return (0, foldM_1.foldM_)(self, (e) => (0, fail_1.fail)(O.some(e)), E.fold(core_1.succeed, () => (0, fail_1.fail)(O.none)));
}
exports.left = left;
//# sourceMappingURL=leftOrFail.js.map