ramda: addIndex(partition) gives incorrect results
Simple example to reproduce:
addIndex(partition)((_,i) => return (i%2) == 0, ['a', 'b', 'c', 'd', 'e'])
actual output: [["a", "c", "e"], ["a", "c", "e"]]
expected output: [["a", "c", "e"], ["b", "d"]]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (18 by maintainers)
i’d rather add
mapi
(and friends) rather than haveaddIndex(map)
promise more than it can deliver.I was noting that if we are going to remove dispatching, then these generalized functions may not matter, and we should worry once again only about lists. For lists, indices are at least somewhat reasonable.
I would certainly be willing to consider removing
addIndex
, but I think it would take a lot of convincing, as it’s one of those tools that helps ease JS people into FP.I think this is a serious point of disagreement. Solving these ergonomic issues was my initial goal with Ramda. While the library has certainly grown beyond that, it’s very hard to see such issues dismissed.
There’s a type error in your version, @jonahx:
R.head
is not of the required type,Chain m => a -> m b
. You could usemap
+head
instead. The erroneous version happens to work, of course, but it’s unwise to rely on implementation details. 😉