These are chat archives for ramda/ramda
@isidorosp if you want a pointfree function then:
const parseData = R.pipe( R.transpose, R.converge(R.map, [ R.pipe(R.head, R.zipObj), R.tail ]), );
If you prefer a pointer function in the middle:
const parseData = R.pipe( R.transpose, ([headers, ...data]) => R.map(R.zipObj(headers), data), );
If you want it in the inverse order, just add a R.reverse at the end of R.pipe.
After transposing you again get an array of arrays: the head is an array with the name of columns, the tail is an array of arrays with the data from each column. Then enters
map accepts two arguments: a function as first argument and the data to map over (array of arrays).
Converge has some branching functions (those inside the array as you can see, R.pipe(R.head, R.zipObj) and R.tail) << these are the branching functions. When the function returned by converge is called, it applies each branching function to the entry data. After that, the results of these calls are passed to the function you are converging (in our case,
R.map). The order is important when you defined the branching functions because they will be passed to R.map in that same order.
So it will work like this
R.converge(R.map, [ R.pipe(R.head, R.zipObj), R.tail ]):
R.pipe(R.head, R.zipObj) is called with the resulting data from the transposition, so you take the head element, pass it to R.zipObj. But R.zipObj is a curried function that takes two arguments (two arrays to zip) but since we called it only with one argument, we get back a function that is expecting one array. This will be the mapping function.
then the second function inside the branching array is called with the same entry data: R.tail. This will return the same array of arrays but without the first element (that one with the headers). So calling R.tail with our entry data gives back an array and this will be the "new" data that we will map over. This result is then passed to the R.map function as second argument. And that's it :D
import * as R from 'ramda'as opposed to
import R from 'ramda'