These are chat archives for ramda/ramda

28th
Mar 2017
Sebastian Andres
@sebandres
Mar 28 2017 00:05
that would return a function that is not curried as I understand @m59peacemaker
Johnny Hauser
@m59peacemaker
Mar 28 2017 00:06
It doesn't
@ram-bot curryN(0, add)(10)
ram-bot
@ram-bot
Mar 28 2017 00:06
[Function: f1]
Johnny Hauser
@m59peacemaker
Mar 28 2017 00:07
@ram-bot curryN(0, add).length
ram-bot
@ram-bot
Mar 28 2017 00:07
0
Sebastian Andres
@sebandres
Mar 28 2017 00:11
@ram-bot
const g = (a,b,c,d) =>   console.log(a,b,c,d)

const fa = R.curryN(0,g)

console.log(fa(1,2,3)) 
//console.log(fa(1)(2)(3)) // <-- Error

const fb = R.curryN(4,g)

console.log(fb(1,2,3,4))
console.log(fb(1)(2)(3)(4))
ram-bot
@ram-bot
Mar 28 2017 00:11
undefined

output

1

1

1
Sebastian Andres
@sebandres
Mar 28 2017 00:12
basically because curryN does an apply on the arguments initially used on the function you still get 1,2,3 on the first call but the function itself has no arguments
because curryN curries the function up to N arguments
@ram-bot
const g = (a,b,c,d) => 
  console.log({a: a,b: b,c: c,d: d})

const fa = R.curryN(0,g)

console.log(fa(1,2,3)) 
//console.log(fa(1)(2)(3)) // <-- Error

const fb = R.curryN(4,g)

console.log(fb(1,2,3,4))
console.log(fb(1)(2)(3)(4))
ram-bot
@ram-bot
Mar 28 2017 00:13
undefined

output

[object Object]

[object Object]

[object Object]
Sebastian Andres
@sebandres
Mar 28 2017 00:13
:(
trying to get the proper output but no joy :P
repl
Sebastian Andres
@sebandres
Mar 28 2017 04:52
@aadityakulkarni I often find that if you articulate the goal in very simple terms it ends up being very similar to what you would write with functions. Perhaps that would help others understand what it is you want to achieve without trying to figure it out (aka assume) things from your examples.
James Forbes
@JAForbes
Mar 28 2017 05:37
@aadityakulkarni check out R.evolve (we'll help you if you run into any issues)
great advice @sebandres
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 09:57
Can anyone have a little look at this please? I'm trying to learn ifElse https://goo.gl/Dp1yy5
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:07
I keep getting a partially applied function back: https://goo.gl/lmsBEI
László Vadász
@maxinteger
Mar 28 2017 10:09
@aaronmcadam https://goo.gl/iqggwe
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:09
Doh I'd tried that before, must have had a bug elsewhere
Thanks @maxinteger!
László Vadász
@maxinteger
Mar 28 2017 10:09
the problem is the ifElse pass the same object to the 3 functions
also the prop have only 2 parameters
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:10
ahh I remember reading that
László Vadász
@maxinteger
Mar 28 2017 10:10
so it immediately evaluated
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:10
Is there a better way to do this then? :)
László Vadász
@maxinteger
Mar 28 2017 10:15
This is my best idea https://goo.gl/c66ut8
if you want pure ramda solution
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:16
I was about to flip prop so that I could partially-apply colours
But yeah, pipe makes sense
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:18
ah, that's sweet
Thanks @kurtmilam. I didn't know about always though
Denis Stoyanov
@xgrommx
Mar 28 2017 10:19
@aaronmcadam https://goo.gl/CYw6iG
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:19
Without looking, I know you've used converge @xgrommx :D
argh not this time :D
Kurt Milam
@kurtmilam
Mar 28 2017 10:20
can replace () => something with R.always( something )
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:20
yeah, is that preferred?
Kurt Milam
@kurtmilam
Mar 28 2017 10:20
which I see that @xgrommx has done in his example :)
Denis Stoyanov
@xgrommx
Mar 28 2017 10:20
@aaronmcadam always = k => () => k
Kurt Milam
@kurtmilam
Mar 28 2017 10:20
AFAIK, they're equivalent.
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:21
Yeah, was just wondering if there's a preferred style
Kurt Milam
@kurtmilam
Mar 28 2017 10:21
always is a little less noisy.
So I think it's up to which you think is easier to read / looks better in your code.
Denis Stoyanov
@xgrommx
Mar 28 2017 10:21
always is K combinator :smile:
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:22
Yeah, I like the consistency of always
Kurt Milam
@kurtmilam
Mar 28 2017 10:22
I usually use always.
or K if I want to keep it short and sweet.
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:22
But now I want to partially apply the colours value
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:25
hmm cool, I was just thinking I didn't want my calling code to have to pass colours
Kurt Milam
@kurtmilam
Mar 28 2017 10:26
Right, you can do that with the last example I shared
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:26
How do you balance the encapsulation of a function when dealing with these sorts of things?
Yeah, I understand that, but the function definition is a bit more complicated now. This is something I'm still developing an intuition for
Kurt Milam
@kurtmilam
Mar 28 2017 10:30
I'd probably do it differently. I don't like the R.always('hard coded string in the ifElse, but I'd have to think a little about how I'd do it.
It seems like a too literal translation of imperative to functional.
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:31
yeah definitely
This code will change to take account of themes anyway
I was just thinking how to reimplement it. Thinking about it now, I might want to use polymorphism instead
But you're right that I'm not stepping back to rethink the logic in a functional way
But I've learned a lot from this so thanks @kurtmilam and everyone :)
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:36
yeah, I was starting down the path of a getColour function earlier :)
Kurt Milam
@kurtmilam
Mar 28 2017 10:36
Sure thing - glad it was helpful. That last version breaks the thing up into more composable functions.
cool :thumbsup:
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:36
I see you're breaking up the functions to be more reusable and composable
hah :+1:
Kurt Milam
@kurtmilam
Mar 28 2017 10:36
exactly. I think that's easier to test and reason about.
Aaron Mc Adam
@aaronmcadam
Mar 28 2017 10:37
yeah, these functions will form part of a theming library so this sort of idea will help me remember to keep the functions simple, thanks :)
Kurt Milam
@kurtmilam
Mar 28 2017 10:38
You're welcome!
Piet Vandeput
@piet-v
Mar 28 2017 11:10
Hi guys, was wondering if there's a simpler way to change a property based on another property?
function addCouponTitle(campaign) {
      return R.evolve({
        coupon: {
          title: R.always(campaign.coupon.description)
        }
      })(campaign);
    }
^ this is a simplified evolve, the real one evolves more props x) Simplified it to indicate my question
Raine Virta
@raine
Mar 28 2017 16:38
@ram-bot console.log(1, 2, [3, 4], {foo: 'bar'})
ram-bot
@ram-bot
Mar 28 2017 16:38
undefined

output

1 2 [ 3, 4 ] { foo: 'bar' }
Denis Stoyanov
@xgrommx
Mar 28 2017 16:44
@ram-bot
new Promise(resolve => setTimeout(() => resolve(100), 1000)).then(x => console.log(x))
ram-bot
@ram-bot
Mar 28 2017 16:44
Promise { <pending> }
Raine Virta
@raine
Mar 28 2017 17:14
@ram-bot
new Promise(resolve => setTimeout(() => resolve(100), 1000)).then(x => console.log(x))
ram-bot
@ram-bot
Mar 28 2017 17:15
Promise { undefined }

output

100
Robert Mennell
@skatcat31
Mar 28 2017 17:25
@xgrommx why are you using a function to invoke a function? Shouldn't you be able to do .thn(console.log)?
@ram-bot new Promise(resolve => resolve(100)).then(console.log)
ram-bot
@ram-bot
Mar 28 2017 17:27
Promise { undefined }

output

100
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:17
doesn't currying the single argument functions slow them down? What's the benefit?
Raine Virta
@raine
Mar 28 2017 18:28

@m59peacemaker https://github.com/ramda/ramda/blob/v0.23.0/src/internal/_curry1.js

looking at the source, i'd guess the reason is R.__

unless you mean currying in some other context
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:29
oh, it does just return the same function
so there's no cost
Raine Virta
@raine
Mar 28 2017 18:30
not exactly
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:31
if (arguments.length === 0 ) return f1
Raine Virta
@raine
Mar 28 2017 18:31
that is not fn
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:31
I mean, not literally "0" cost
the same function with a touch of overhead
Raine Virta
@raine
Mar 28 2017 18:33
what you pasted is for returning the function if it's called without arguments
@ram-bot always()()
ram-bot
@ram-bot
Mar 28 2017 18:33
[Function: f1]
Denis Stoyanov
@xgrommx
Mar 28 2017 18:35
@skatcat31 because context of call
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:36
I think we must be talking past one another
curryN(1, fn) returns a function that returns itself when not passed any arguments
Denis Stoyanov
@xgrommx
Mar 28 2017 18:38
@m59peacemaker nAry
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:38
oh yeah. and the length is 1
but what good is changing a function length?
I mean, unless it's wrong to begin with
Denis Stoyanov
@xgrommx
Mar 28 2017 18:39
@m59peacemaker for arity
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:39
Still lost. I get why you'd want to fix the arity when currying
Denis Stoyanov
@xgrommx
Mar 28 2017 18:40
@m59peacemaker unary, binary
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:40
can you show me an example of when you have a function that needs curryN(1 called on it?
The only one I can think of is if you had something that is going to tick a bunch of times and you want to pass it a function that acts as a noop until it produces a value
Denis Stoyanov
@xgrommx
Mar 28 2017 18:44
@m59peacemaker I think never
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:44
So Ramda only does it for the placeholder?
lemme go tests what a placeholder does in that case
Raine Virta
@raine
Mar 28 2017 18:45
same as not passing anything
maybe it's just so that passing placeholder works consistently across functions of varying arity
Johnny Hauser
@m59peacemaker
Mar 28 2017 18:47
foo(1, 2, 3)
curryN(1, foo)(1, 2, 3)
curryN(1, foo)(__)(1, 2, 3)
all identical
yeah
so if Ramda didn't have placeholders, it would make sense not to curry arity < 2 functions?
Raine Virta
@raine
Mar 28 2017 18:55
there must be some point in returning the same function if it's called without arguments