@CrossEye Would you help me understand your suggestion, please?
f = R.assoc('id')
g = R.zipWith( f );
R.converge(g, R.keys, R.values);
I understand that we are partially applying arguments.assoc
takes 3 arguments. The last one is the list itself.
But what happens with the second one?
R.zipWith
with a function that accepts two arguments (1. and 2. above) will then be expecting one array of 1. and one array of 2.
R.keys
gives you the array of 1.s and R.values
an array of 2.s
@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)