add-index

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
1 KB
Creates a new list iteration function from an existing one by adding two new parameters to its callback function: the current index, and the entire list.
1 contributor
Install add-index as a package?
Copied
npm i @bit/justin-capalbo.ramda.add-index
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
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';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
addIndex (
fn:Function
) : Function

Creates a new list iteration function from an existing one by adding two new parameters to its callback function: the current index, and the entire list.

This would turn, for instance, R.map function into one that more closely resembles Array.prototype.map. Note that this will only work for functions in which the iteration callback function is the first parameter, and where the list is the last parameter. (This latter might be unimportant if the list parameter is not used.)

Example
const mapIndexed = R.addIndex(R.map);
     mapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']);
     //=> ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
Argument
fn: Function

A list iteration function that does not pass index or list to its callback

Returns
Function

An altered list iteration function that passes (item, index, list) to its callback

Help and resources