Skip to content

accumulate

Subhajit Sahu edited this page Feb 3, 2021 · 15 revisions

Produces accumulating values. 🏃 📼 📦 🌔 📒

Similar: map, filter, reject, reduce, accumulate.

iterable.accumulate(x, fr, [acc]);
// x:   an iterable
// fr:  reduce function (acc, v, i, x)
// acc: initial value
const iterable = require("extra-iterable");

var x = [1, 2, 3, 4];
[...iterable.accumulate(x, (acc, v) => acc+v)];
// [ 1, 3, 6, 10 ]

[...iterable.accumulate(x, (acc, v) => acc+v, 100)];
// [ 101, 103, 106, 110 ]

references

Clone this wiki locally