"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.collectAllWhile = void 0;
// ets_tracing: off
const CK = __importStar(require("../../../Collections/Immutable/Chunk"));
const L = __importStar(require("../../../Collections/Immutable/List"));
const Tp = __importStar(require("../../../Collections/Immutable/Tuple"));
const Function_1 = require("../../../Function");
const Fold = __importStar(require("./fold"));
const Map = __importStar(require("./map"));
/**
 * Accumulates incoming elements into a chunk as long as they verify predicate `p`.
 */
function collectAllWhile(p) {
    return (Map.map_(Fold.fold(Tp.tuple(L.empty(), true), Tp.get(1), ({ tuple: [as, _] }, a) => {
        if (p(a)) {
            return Tp.tuple(L.prepend_(as, a), true);
        }
        else {
            return Tp.tuple(as, false);
        }
    }), ({ tuple: [is, _] }) => CK.from(L.reverse(is))));
}
exports.collectAllWhile = collectAllWhile;
//# sourceMappingURL=collectAllWhile.js.map