Example 1 — Official Sample: Growing Strings
Join digits one at a time and keep every in-between string.
const digits = ['1', '2', '3', '4'];
const appender = (a, b) => [a + b, a + b];
console.log(R.mapAccum(appender, 0, digits));
// ['01234', ['01', '012', '0123', '01234']] How It Works
- Pair out.
appenderreturns[a + b, a + b]— the same value as the next accumulator and as the new item. - Number + string.
0 + '1'is the text'01', so the accumulator becomes a growing string. - Collect. Each step’s second value goes into the new list:
'01','012', … - Final pair. The last accumulator
'01234'comes first, then the list.
