These are chat archives for ramda/ramda

6th
Apr 2015
James Forbes
@JAForbes
Apr 06 2015 06:02
Hey guys. Have you come across this pattern before?
function f(a,b,c){
  return c ? 

    a + b + c : 

  f.bind.apply(f,[null].concat([].slice.apply(arguments)))
}
Self currying function
Walle Cyril
@GrosSacASac
Apr 06 2015 06:04
what does come across mean ?
James Forbes
@JAForbes
Apr 06 2015 06:07
Come across, as in, seen it before
Walle Cyril
@GrosSacASac
Apr 06 2015 06:09
I have seen it
James Forbes
@JAForbes
Apr 06 2015 06:13
cool! Where?
Walle Cyril
@GrosSacASac
Apr 06 2015 06:15
I watched tutorials about functional programming a while ago with douglas
James Forbes
@JAForbes
Apr 06 2015 06:21
Cool. Well I only just realised a function could take responsibility for its own partial application. And yeah it is a bit uglier than calling a curry function. But it is also pretty cool that a function can take responsibility of its own destiny, and to be so explicit about its end usage.

And I'd prefer it to this pattern.

f = function(a){
  return function(b){
    return function(c){
       return a + b+ c
    }
  }
}

Because it is much harder to see what is going on in the body. And f(1,2,3) wouldn't execute.

Walle Cyril
@GrosSacASac
Apr 06 2015 06:41
why would it better than wrapping the function in R.curry( ) ?
James Forbes
@JAForbes
Apr 06 2015 06:57
I'm not sure it is. It is probably always better to call R.curry, or _.curry etc. But a few reasons that come to mind.
  1. often I am hacking away in a REPL with no libraries at the ready.
  2. perhaps you can't include libraries in a client/employers project, and perhaps currying makes them scared.
  3. Simpler to curry inline because you know more about a given functions context than R.curry does.
  4. Arguably, less overhead.
Honestly, I'd probably stick with R.curry.
David Chambers
@davidchambers
Apr 06 2015 07:48
@JAForbes, your code has an error:
> f(1, 2, 3)
6
> f(0, 0, 0)
[Function]
You should use arguments.length >= 3 as the check rather than c.
James Forbes
@JAForbes
Apr 06 2015 08:23
@davidchambers right you are
Walle Cyril
@GrosSacASac
Apr 06 2015 09:32
Yes