sequency
Version:
Functional sequences for processing iterable data in JavaScript
25 lines • 934 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Fold = void 0;
var Fold = /** @class */ (function () {
function Fold() {
}
/**
* Accumulates all elements of the sequence into a single result by applying the given `operation` starting with
* the `initial` value. The result of the last operation will be passed as accumulated value to the getNext invocation
* of the operation until all elements of the sequence are processed.
*
* @param {R} initial
* @param {(acc: R, element: T) => R} operation
* @returns {R}
*/
Fold.prototype.fold = function (initial, operation) {
var result = initial;
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
result = operation(result, item.value);
}
return result;
};
return Fold;
}());
exports.Fold = Fold;
//# sourceMappingURL=fold.js.map