selfrefactor / rambda

Faster and smaller alternative to Ramda

Home Page:https://selfrefactor.github.io/rambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

index accumulates when addIndex is put inside pipe

ywchan2005 opened this issue · comments

when addIndex is composed by pipe

const foo = R.pipe(
  R.addIndex(R.map)((x, idx) => x+'-'+idx),
)

indices (i.e. idx) received are correct in the first call

console.log(foo(['a', 'b', 'c', 'd']))
// => ['a-0', 'b-1', 'c-2', 'd-3']

however, indices seem to accumulate in the second call

console.log(foo(['a', 'b']))
// => ['a-4', a-5']

and also in later calls

const result = foo(['a', 'b', 'c'])
// => ['a-6', 'b-7', 'c-8']

sample code

So this method addIndex is not added by me, rather than from a contributor. As much I can see, I cannot solve it in simple way, so I will go and remove it.

New version will be published in the coming days, so you still have time to suggest solution and in this case the new version will contain your code.