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 this, but didn't work:

pipe( map(assoc('data', __, {})), map(assoc('id', multiply(100, prop('data', __)))) )(range(1, 1000))

If the approach is to use two pipes, then there has to be some way to pipe over two different arrays simultaneously. How can this be implemented?

Answer1:

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))

Answer2:

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))

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:Pipe on multiple data in ramda