## Where communities thrive

• Join over 1.5M+ people
• Join over 100K+ communities
• Free without limits
##### Activity
• Jan 31 2019 22:17
CrossEye commented #2779
• Jan 31 2019 21:04
ArturAralin commented #2779
• Jan 31 2019 20:08
CrossEye commented #2779
• Jan 31 2019 18:56
buzzdecafe commented #2631
• Jan 31 2019 18:09
ArturAralin commented #2779
• Jan 31 2019 16:18
CrossEye commented #2779
• Jan 31 2019 16:10
CrossEye commented #2631
• Jan 31 2019 16:06
CrossEye commented #2777
• Jan 31 2019 14:44
ArturAralin opened #2779
• Jan 31 2019 07:39
inferusvv commented #2631
• Jan 31 2019 03:07
sespinozj commented #2771
• Jan 31 2019 02:33
• Jan 31 2019 02:26
JeffreyChan commented #2777
• Jan 30 2019 14:30
CrossEye closed #2777
• Jan 30 2019 12:13
• Jan 30 2019 01:42
JeffreyChan commented #2777
• Jan 29 2019 21:06
• Jan 29 2019 16:28
CrossEye commented #2777
• Jan 29 2019 15:50
mbostock commented #2772
• Jan 29 2019 15:48
CrossEye commented #2772
Scott Sauyet
@CrossEye
Thank you @algesten. I struggle to explain these things succinctly.
Martin Algesten
@algesten
not sure i managed to. but i wanted to take a stab.
Aldwin Vlasblom
@Avaq

@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.

Scott Sauyet
@CrossEye
An important point here is the parallel between keys and values. They are ordered in parallel. The fourth entry in the list of values is the value of the property of the object at the fourth entry in the list of keys. Without that, this would not work.
Scott Sauyet
@CrossEye
A version of the same technique where that association is not so important would be R.compose(R.map(R.apply(R.assoc('id'))), R.toPairs). The tradeoff is having to call R.apply. But this might be a little cleaner.
Martin Algesten
@algesten
well done avoiding R.pipe there ;)
Scott Sauyet
@CrossEye
Just for you. I wrote it as pipe because that's how I think, and reversed it to compose :smile:
Martin Algesten
@algesten
haha! :D
just out of curiosity. does Object.keys guarantee an order?
or that multiple invocations will have the same order as a result.
Scott Sauyet
@CrossEye
Very big point of contention now. #1067.
Scott Sauyet
@CrossEye
It is not really consisyent with our notion of equals. Two things we think of as equal could have different order of keys. I'm proposing a change, but there's significant opposition.
Martin Algesten
@algesten
I'm reading. just now at the bit where jdalton appear to be wilfully obtuse regarding the natural order of a list.
Scott Sauyet
@CrossEye
He's not just trolling, even if it sometimes feels that way. He does have serious points to make. And decisions here are clearly not as obvious to everyone as I would have thought. Lots of smart people with lots of different opinions.
John-David Dalton
@jdalton
:hear_no_evil:
Martin Algesten
@algesten
:blush:
Scott Sauyet
@CrossEye
... and jdalton is one of them :angel:
Raine Virta
@raine

I think the arrow syntax is a bit too loose

let foo = (a) => ... // ok
let bar = () => ... // ok
let baz = a => ... // ok
let xyz = => ... // not ok

however in case of map(x => x*x) I can understand without parens it's more readable

John-David Dalton
@jdalton
Arrow funcs are nice
I donno why skinny arrow wasn't done (no lexical bind)
like CS. There was prolly a ton of discussion (as per usual)
Alex Schenkman
@alesch
@algesten @Avaq @CrossEye Thank you all for the explanations. I’ll have to study them more.
@CrossEye You said you used compose but you thought of it with pipe. How would it be with pipe? In case it becomes easier to read for me.
Scott Sauyet
@CrossEye
R.pipe(R.toPairs, R.map(R.apply(R.assoc('id')))) -- just reversing the parameter order.
Aldwin Vlasblom
@Avaq

@alesch pipe is just compose but reversed: pipe(a, b, c) === compose(c, b, a)

I think compose is meant to resemble nested-function calling, like so: compose(a, b, c)(x) looks like a(b(c(x)))

And pipe is meant to resemble piping, like so: pipe(a, b, c)(x) looks like x > a | b | c

Or that's how I think of them anyway. ;)
John-David Dalton
@jdalton
trying to come up with a better name for useWith and converge. It looks like useWith may be created by way of converge.
naming these things is hhaaaarrrdd grumble grumble
John-David Dalton
@jdalton
modArgs and distArgs woo
John-David Dalton
@jdalton
still not great
but betterish
Raine Virta
@raine
mapArgs
John-David Dalton
@jdalton
that makes me think of 1 function to map over args
Raine Virta
@raine
yeah that's true
John-David Dalton
@jdalton
it could be maybe
converge -> modArgs and useWith -> modPerArg
John-David Dalton
@jdalton
oh snao
so I created a createModArgs
that takes a resolver
the resolver accepts arg, index, arguments (like value, index, array)
it's used to then create a function that passes the transforms args based on the resolves of the resolver
so for useWith the resolver would be identity and for converge it would be function(value, index, args) { return args }
could be baseModArgs(func, transforms, resolver)
Jethro Larson
@jethrolarson
About half the time I use useWith I actually want the W combinator
W (foo)(x) == foo (x)(x)
Jethro Larson
@jethrolarson
Well, that's only true if everything is manually curried, including compose
Matthew Steedman
@knubie
@jdalton I actually think converge makes a lot of sense as a name
Dominik Dumaine
@Bondifrench
Hi all, is there a function in Ramda that loops over the values of an array, and transforms them to keys of an object ie ['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
John-David Dalton
@jdalton
@knubie you can be wrong it's ok ; )
Jethro Larson
@jethrolarson
Converge made sense to me. UseWith not so much