These are chat archives for ramda/ramda

9th
Sep 2017
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 13:53 UTC
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 UTC
Do you want R.converge( R.multiply, [R.identity, R.identity] )([10]) ?
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:27 UTC
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 UTC
ah ok
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:30 UTC
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 UTC

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 UTC
I tried replacing Ramda's multiply with R.curry((a, b) => a * b)) - it doesn't work
James Forbes
@JAForbes
Sep 09 2017 14:32 UTC
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 UTC

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

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 UTC
Ah, I see!
James Forbes
@JAForbes
Sep 09 2017 14:39 UTC
but when we manually curry it gets around that
:D
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:40 UTC
Is this what you had in mind when converge was written?
James Forbes
@JAForbes
Sep 09 2017 14:42 UTC
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 UTC
It does work with R.unary(R.multiply)
James Forbes
@JAForbes
Sep 09 2017 14:43 UTC
Yeah that's another way to work around it
Karthik Iyengar
@karthik_i_twitter
Sep 09 2017 14:43 UTC
Thanks for all the help @JAForbes
:-D
James Forbes
@JAForbes
Sep 09 2017 14:43 UTC
My pleasure @karthik_i_twitter :)
Karthik Iyengar
@karthikiyengar
Sep 09 2017 18:51 UTC
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 UTC
@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 UTC
@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 UTC
@kurtmilam here is another mirror implementation: chain(flip(concat), reverse)