Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

map-accum

v0.26.1arrow_drop_down
v0.26.1
STATUS
Passing
DOWNLOADS
25
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 months ago
SIZE
976 B
subject
The `mapAccum` function behaves like a combination of map and reduce; it
1 contributor
Use map-accum in your project ?
Copied
npm i @bit/ramda.ramda.map-accum
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
revert changes
reload
toggle layout
maximize
mapAccum(appender, 0, digits);
modifieddraft
chevron_left
chevron_right
mapAccum (
fn:Function,
acc:*,
list:Array
) : *

The mapAccum function behaves like a combination of map and reduce; it applies a function to each element of a list, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list.

The iterator function receives two arguments, acc and value, and should return a tuple [acc, value].

Example
const digits = ['1', '2', '3', '4'];
     const appender = (a, b) => [a + b, a + b];

     R.mapAccum(appender, 0, digits); //=> ['01234', ['01', '012', '0123', '01234']]
Arguments
fn: Function

The function to be called on every element of the input list.

acc: *

The accumulator value.

list: Array

The list to iterate over.

Returns
*

The final, accumulated value.