These are chat archives for ramda/ramda

8th
Jul 2017
Eugene Krayni
@eakray
Jul 08 2017 00:01
nice
Vadim Nekrasov
@barbiturat
Jul 08 2017 05:59

Hello everyone! Could somebody explain me logic of “sequence” method?
Why does this code work?

const plusOne = x => x + 1;
const plusTwo = x => x + 2;
const plusThree = x => x + 3;

sequence(always, [plusOne, plusTwo, plusThree])(1) // => [2, 3, 4]

In the documentation http://ramdajs.com/docs/#sequence i see that this method accepts "Traversable of Applicative”. But i pass an array of simple functions! A simple, not curried function is an Applicative?

If yes, why in the doc of “ap” method said: “Also treats curried functions as applicatives."
Vadim Nekrasov
@barbiturat
Jul 08 2017 06:05
So, what kind of functions can I treat as applicatives in ramda?
Vadim Nekrasov
@barbiturat
Jul 08 2017 06:16
And what else of standard js-objects can be considered applicatives?
Kurt Milam
@kurtmilam
Jul 08 2017 07:44
@barbiturat I believe that a function with arity=one can be considered a curried function.
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:10
@kurtmilam are you talking only about “sequence” method now?
Kurt Milam
@kurtmilam
Jul 08 2017 08:12
No, I mean in general.
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:13
Thank you!
Denis Stoyanov
@xgrommx
Jul 08 2017 08:13
:smile:
@barbiturat for function of = K, K = x => y => x, ap = S, S = x => y => z => x(z)(y(z))
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:14
:)
glad to see you here, Denis! )
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:20
of = K, K = x => y => x, ap = S, S = x => y => z => x(z)(y(z))
@xgrommx Where have you found it?
Kurt Milam
@kurtmilam
Jul 08 2017 08:20
When you curry a function with x-arity, you end up with x functions, each with one-arity (Haskell-style currying, not Ramda-style). So if you start out with a single one-arity function and curry it, you'll end up with a single one-arity function.
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:30
Could somebody describe what type of data accepts “chain” method for a second argument?
Any functor?
Vadim Nekrasov
@barbiturat
Jul 08 2017 08:52
I see that it works with arrays and with functions. So what the restrictions for type of data?
Ryan Stegmann
@rstegg
Jul 08 2017 10:04
what is the benefit of having arity?
Kurt Milam
@kurtmilam
Jul 08 2017 10:08
@rstegg Not sure I understand the question. Every function has arity. That's simply the number of arguments the function expects.
() => true // 0-arity
x => x // 1-arity
( x, y ) => x // 2-arity
Ryan Stegmann
@rstegg
Jul 08 2017 10:12
@kurtmilam javascript doesn't curry it's functions though, so calling out the arity seems partial to languages that advertise currying
i was wondering if there was a certain benefit, i.e. performance
Kurt Milam
@kurtmilam
Jul 08 2017 10:13
R.curry? We're in the Ramda gitter. And whether or not a language curries its functions, the functions will still have an arity.
You can also manually curry your functions in JS. I often do: f => g => h => f( g( h ) ). The benefit of having functions with 1-arity is that they are easier to compose. R.curry does something slightly different. It allows you to call the resulting function with one or more arguments until all of the required arguments have been supplied.
So you can call R.add( 1 )( 2 ) or R.add( 1, 2 ).
Ryan Stegmann
@rstegg
Jul 08 2017 10:18
gotcha, thanks!
Kurt Milam
@kurtmilam
Jul 08 2017 10:23
:thumbsup:
Ryan Stegmann
@rstegg
Jul 08 2017 10:33
i was asking why keeping track of arity was important, but not sure how to ask
but you answered the question, thank you
Vadim Nekrasov
@barbiturat
Jul 08 2017 10:40

One more question. Why does this code still work? )

const plusOne = x => x + 1;
const plusTwo = x => x + 2;
const plusThree = x => x + 3;

const fn = curry(function(a, b) {});

sequence(fn, [plusOne, plusTwo, plusThree])(1) // => [2, 3, 4]

I have surprised because function “fn” should return nothing

I slill don’t understand the logic of “sequence" method
Syaiful Bahri
@syaiful6
Jul 08 2017 11:39
@barbiturat the first argument to sequence isn't used if the array passed to sequence is not empty.
that first argument is mean to be Applicative.of described in Fantasy-Land.
Vadim Nekrasov
@barbiturat
Jul 08 2017 12:41
@syaiful6 thank you! It is strange that ramda claims me to pass a first argument (that should be, at lest function of artiy == 2). If ramda doesn’t even use it
Denis Stoyanov
@xgrommx
Jul 08 2017 12:55
@barbiturat this is js, and it is a bullshit for normal fp