These are chat archives for ramda/ramda

9th
Sep 2017
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 13:53
I've been looking at this for the past 30 mins and I can't figure out why this doesn't work: http://ramdajs.com/repl/?v=0.24.1#?const%20fn%20%3D%20R.converge%28R.call%2C%20%5BR.identity%2C%20R.multiply%5D%29%3B%0Afn%2810%29%0A
Shouldn't this just return 100?
James Forbes
@JAForbes
Sep 09 2017 14:24
Do you want R.converge( R.multiply, [R.identity, R.identity] )([10]) ?
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:27
Not really, I've extracted this from a bigger pipeline - what I want is the multiply function to be curried with 10, and eventually called with the output of R.identity(10) (I'll replace this with another function later)
James Forbes
@JAForbes
Sep 09 2017 14:29
ah ok
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:30
It's very strange. I've also considered that it's returning a function, maybe because the arity of multiply is greater than 2. But that is not the case.
James Forbes
@JAForbes
Sep 09 2017 14:31

yeah converge isn't behaving how I'd expect, I think it's sniffing the arities of the inputs to determine the arity of the final function.

var fn = R.converge((a,b) => [a,b], [R.identity, R.multiply])

I'd expect this to evaluate to: [10, multiply(10)] but instead I get a curried function

so something's up
yeah I think you're right
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:32
I tried replacing Ramda's multiply with R.curry((a, b) => a * b)) - it doesn't work
it uses the max arity of the input functions
if you replace it with a => b => a * b it will work most likely
James Forbes
@JAForbes
Sep 09 2017 14:35

looks like @davidchambers was the furthest back commit author for that line I can see that introduced the max check https://github.com/ramda/ramda/blob/v0.24.1/src/converge.js#L37

Which is somewhat ironic considering a recent proposal to sanctuary to only include unary currying

Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:36
ramda/ramda#1404 - Is this related?
James Forbes
@JAForbes
Sep 09 2017 14:37
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:37
I tried some stuff with using R.binary - but I shot myself in the foot.
James Forbes
@JAForbes
Sep 09 2017 14:37
Note the unary currying of multiply
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:38
Isn't R.curry supposed to do that?
James Forbes
@JAForbes
Sep 09 2017 14:38
They're not 100% equivalent
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:39
Some other gentleman proposed this: https://goo.gl/Q6Q4Df
James Forbes
@JAForbes
Sep 09 2017 14:39

var mul = R.curry( (a,b) => a * b )

mul(2,2) is valid, so R.curry reports an arity / argument length of 2

Which tells converge to wait for another arg
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:39
Ah, I see!
James Forbes
@JAForbes
Sep 09 2017 14:39
but when we manually curry it gets around that
:D
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:40
Is this what you had in mind when converge was written?
James Forbes
@JAForbes
Sep 09 2017 14:42
R.curry is an abstraction, and it's leaking. I don't know if converge should do the arity check it's doing, perhaps it makes sense in another corner case.
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:42
It does work with R.unary(R.multiply)
James Forbes
@JAForbes
Sep 09 2017 14:43
Yeah that's another way to work around it
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:43
Thanks for all the help @JAForbes
:-D
James Forbes
@JAForbes
Sep 09 2017 14:43
My pleasure @karthik_i_twitter :)
Karthik Iyengar
@karthikiyengar
Sep 09 2017 18:51
Would there be a more err…ramda way of writing this function? (a, b) => getFunction(a)(b)
The function getFunction returns has access to b via closure.
Philipp Wille
@Yord
Sep 09 2017 18:59
@karthikiyengar do you search for something like:
const getFunction = a => b => [a, b] // or whatever

const f = uncurryN(2, getFunction)

f(1, 2)
Karthik Iyengar
@karthikiyengar
Sep 09 2017 19:02
@Yord - Thanks :-) But I should go for another approach. I’m creating monsters that I won’t understand after a week.
Michael Hurley
@buzzdecafe
Sep 09 2017 23:02
@kurtmilam here is another mirror implementation: chain(flip(concat), reverse)