Pipe On Multiple Data In Ramda
How can I pipe on multiple data arrays? Ultimately I want to achieve something like this: const data = [{id: 1, data:100}, {id: 2, data: 200}, {id: 3, data: 3000}, ... ] I tried
Solution 1:
I suggest this:
R.map(n => ({id: n, data: 100 * n}), R.range(1, 1000))
A point-free solution is available, but it's not elegant:
R.map(R.converge(R.merge,
[R.objOf('id'),
R.compose(R.objOf('data'), R.multiply(100))]),
R.range(1, 10))
Solution 2:
This is the best I could come up with in pointfree style, a bit hacky in that the number given to repeat should match the amount of keys given to zipObj. Extra keys could be added with an assoc after the evolve
map(
pipe(
repeat(__, 2),
zipObj(['data', 'id']),
evolve({
data: multiply(100)
})
)
)(range(1, 1000))
Post a Comment for "Pipe On Multiple Data In Ramda"