sequency
Version:
Functional sequences for processing iterable data in JavaScript
28 lines • 1.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.FoldIndexed = void 0;
var FoldIndexed = /** @class */ (function () {
function FoldIndexed() {
}
/**
* 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 as well as the `index` of the current element (zero-based) until all elements of the sequence
* are processed.
*
* @param {R} initial
* @param {(index: number, acc: R, element: T) => R} operation
* @returns {R}
*/
FoldIndexed.prototype.foldIndexed = function (initial, operation) {
var result = initial;
var index = 0;
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
result = operation(index, result, item.value);
index++;
}
return result;
};
return FoldIndexed;
}());
exports.FoldIndexed = FoldIndexed;
//# sourceMappingURL=foldIndexed.js.map