I used to write something like
_.map(items, (item, index) => {});
with lodash. Usually I don't need index
but sometimes it's useful.
I'm migrating to Ramda now:
R.map((item, index) => {}, items);
index
is undefined
. Sure, I can create variable index
in upper scope and increment it every time in map
body but it's kinda wrong from FP point of view that Ramda stands for. So is there's any build in way of getting iteration index?
You can also use mapIndexed from Ramda Adjunct which uses
R.addIndex
under the hood.It also offsers a reduceIndexed
Check out
addIndex
:Example from the docs: