sequency
Version:
Functional sequences for processing iterable data in JavaScript
29 lines • 1.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Partition = void 0;
var Partition = /** @class */ (function () {
function Partition() {
}
/**
* Evaluates the given `predicate` for each element of the sequence and assorts each element into one of two lists
* according to the result of the predicate. Returns both lists as an object.
*
* @param {(value: T) => boolean} predicate
* @returns {{true: Array<T>; false: Array<T>}}
*/
Partition.prototype.partition = function (predicate) {
var arrayTrue = [];
var arrayFalse = [];
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
if (predicate(item.value)) {
arrayTrue.push(item.value);
}
else {
arrayFalse.push(item.value);
}
}
return { "true": arrayTrue, "false": arrayFalse };
};
return Partition;
}());
exports.Partition = Partition;
//# sourceMappingURL=partition.js.map