Pipe on multiple data in ramda

How can I connect to multiple datasets? Ultimately, I want to achieve something similar:

const data = [{id: 1, data:100}, {id: 2, data: 200}, {id: 3, data: 3000}, ... ] 

I tried this but did not 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 must be some way to connect two different arrays at the same time. How can this be implemented?

0
source share
2 answers

I suggest the following:

 R.map(n => ({id: n, data: 100 * n}), R.range(1, 1000)) 

A point solution is available, but it is not elegant:

 R.map(R.converge(R.merge, [R.objOf('id'), R.compose(R.objOf('data'), R.multiply(100))]), R.range(1, 10)) 
+4
source

This is the best I could think of in the style of pointfree, a bit hacked in that the number specified for retry should match the number of keys given by zipObj. Additional keys can be added with the associate after evolution

 map( pipe( repeat(__, 2), zipObj(['data', 'id']), evolve({ data: multiply(100) }) ) )(range(1, 1000)) 
0
source

Source: https://habr.com/ru/post/1263873/


All Articles