"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.findM = exports.findM_ = void 0;
const tracing_1 = __importStar(require("../../../../Tracing"));
const fileName_1 = "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/findM.ts";
const T = __importStar(require("../../../../Effect"));
const O = __importStar(require("../../../../Option"));
const definition_1 = require("../definition");
/**
 * Returns the first element that satisfies the effectful predicate.
 */
function findM_(self, f) {
    return T.suspend(() => {
        const iterator = self.arrayLikeIterator();
        let next;
        const loop = (iterator, array, i, length) => {
            if (i < length) {
                const a = array[i];
                return T.chain_(f(a), (r) => r ? T.succeed(O.some(a), fileName_1 + ":26:24") : loop(iterator, array, i + 1, length), fileName_1 + ":25:24");
            }
            else if (!(next = iterator.next()).done) {
                return loop(iterator, next.value, 0, next.value.length);
            }
            else {
                return T.succeed(O.none, fileName_1 + ":31:25");
            }
        };
        next = iterator.next();
        if (!next.done) {
            return loop(iterator, next.value, 0, next.value.length);
        }
        else {
            return T.succeed(O.none, fileName_1 + ":40:23");
        }
    }, fileName_1 + ":13:19");
}
exports.findM_ = findM_;
/**
 * Returns the first element that satisfies the effectful predicate.
 */
function findM(f) {
    return (self) => findM_(self, f);
}
exports.findM = findM;
//# sourceMappingURL=findM.js.map