"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.provideLayer = exports.provideLayer_ = exports.provideSomeLayer = void 0;
// ets_tracing: off
const L = __importStar(require("../../Layer"));
const T = __importStar(require("../_internal/effect"));
const M = __importStar(require("../_internal/managed"));
const chain_1 = require("./chain");
const managed_1 = require("./managed");
const repeatEffectChunkOption_1 = require("./repeatEffectChunkOption");
/**
 * Provides a layer to the given effect
 */
function provideSomeLayer(layer) {
    return (self) => provideLayer_(self, layer["+++"](L.identity()));
}
exports.provideSomeLayer = provideSomeLayer;
/**
 * Provides a layer to the given effect
 */
function provideLayer_(self, layer) {
    return (0, chain_1.chain_)((0, managed_1.managed)(M.gen(function* (_) {
        const r = yield* _(L.build(layer));
        const as = yield* _(M.provideAll_(self.proc, r));
        return T.provideAll_(as, r);
    })), repeatEffectChunkOption_1.repeatEffectChunkOption);
}
exports.provideLayer_ = provideLayer_;
/**
 * Provides a layer to the given effect
 */
function provideLayer(layer) {
    return (self) => provideLayer_(self, layer);
}
exports.provideLayer = provideLayer;
//# sourceMappingURL=provideSomeLayer.js.map