"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.map = exports.map_ = exports.foldM = exports.foldM_ = exports.fold = exports.fold_ = exports.tap = exports.tap_ = exports.fromPull = exports.done = exports.end = exports.halt = exports.chunk = void 0;
// ets_tracing: off
require("../../Operator");
const C = __importStar(require("../../Cause/core"));
const A = __importStar(require("../../Collections/Immutable/Chunk"));
const E = __importStar(require("../../Exit/api"));
const Function_1 = require("../../Function");
const O = __importStar(require("../../Option"));
const T = __importStar(require("../_internal/effect"));
function chunk(as) {
    return E.succeed(as);
}
exports.chunk = chunk;
function halt(cause) {
    return E.halt((C.map(O.some)(cause)));
}
exports.halt = halt;
exports.end = E.fail(O.none);
function done(take) {
    return T.done(take);
}
exports.done = done;
function fromPull(pull) {
    return (T.foldCause_(pull, (c) => (O.fold_(C.sequenceCauseOption(c), () => exports.end, halt)), chunk));
}
exports.fromPull = fromPull;
function tap_(take, f) {
    return T.asUnit(E.forEach_(take, f));
}
exports.tap_ = tap_;
function tap(f) {
    return (take) => tap_(take, f);
}
exports.tap = tap;
/**
 * Folds over the failure cause, success value and end-of-stream marker to
 * yield a value.
 */
function fold_(take, end, error, value) {
    return E.fold_(take, (x) => (O.fold_(C.sequenceCauseOption(x), () => end, error)), value);
}
exports.fold_ = fold_;
/**
 * Folds over the failure cause, success value and end-of-stream marker to
 * yield a value.
 */
function fold(end, error, value) {
    return (take) => fold_(take, end, error, value);
}
exports.fold = fold;
/**
 * Effectful version of `Take#fold`.
 *
 * Folds over the failure cause, success value and end-of-stream marker to
 * yield an effect.
 */
function foldM_(take, end, error, value) {
    return E.foldM_(take, (x) => (O.fold_(C.sequenceCauseOption(x), end, error)), value);
}
exports.foldM_ = foldM_;
/**
 * Effectful version of `Take#fold`.
 *
 * Folds over the failure cause, success value and end-of-stream marker to
 * yield an effect.
 */
function foldM(end, error, value) {
    return (take) => foldM_(take, end, error, value);
}
exports.foldM = foldM;
function map_(take, f) {
    return E.map_(take, A.map(f));
}
exports.map_ = map_;
function map(f) {
    return (take) => map_(take, f);
}
exports.map = map;
//# sourceMappingURL=index.js.map