@alesch I also found CrossEyes answer pretty astounding, so I picked it apart in the REPL. Let's start with converge
:
//converge(f, a, b)(x) === f(a(x), b(x))
//so:
R.converge(R.zipWith(R.assoc('id')), R.keys, R.values)(x) //===
R.zipWith(R.assoc('id'))(R.keys(x), R.values(x)) //===
R.zipWith(R.assoc('id'), R.keys(x), R.values(x))
Now R.keys
and R.values
both produce lists. One containing the ID's (keys
) and the other containing objects (values
). And as it happens, R.zipWith(f)
wants two lists, and it'll pass a pair of items (taken from both lists) into f
so that f
may produce a single item for the returned list.
In this case we use R.assoc('id')
as our f
(zipper function), which will receive the ID from the first list, and the object from the second and return a new object on which the "id" property will have been set.
Object.keys
guarantee an order?
converge
-> modArgs
and useWith
-> modPerArg
createModArgs
resolver
arg, index, arguments
(like value, index, array)
useWith
the resolver would be identity
and for converge
it would be function(value, index, args) { return args }
baseModArgs(func, transforms, resolver)
['FY', 'Q3', 'Q2'] => {'FY': [ some filtered stuff here], 'Q3': [ 'some other stuff' ], 'Q2': [ ]}
Use case is when getting some stuff from SQL and transforming into more json like structure