These are chat archives for ramda/ramda

27th
May 2016
Rafe
@rjmk
May 27 2016 00:31
I downloaded Idris and had a play around and success :tada:
David Chambers
@davidchambers
May 27 2016 02:09
Congrats, @rjmk!
Brad Compton (he/him)
@Bradcomp
May 27 2016 03:31
:-O
LeonineKing1199
@LeonineKing1199
May 27 2016 04:39

@CrossEye

So to me, currying is more akin to creating a bound function object(instead of apply). It's actually pretty easy to abuse JS's treatment of the arguments object.

Consider:

// simple accumulator
const variadic = function() {
  return reduce((acc, item) => (acc + item), 0, values(arguments))
}

// first round binding
const curriedVariadic = variadic.bind(0, 1, 2, 3, 4)
console.log(curriedVariadic())

// second round
const superExtraCurried = curriedVariadic.bind(5, 6, 7, 8, 9, 10)
console.log(superExtraCurried())

// 10
// 50

So basically, we need to deal with placeholder arguments now. If we have f(x, y, z) and someone passes in a placeholder in the middle, for example, we need a function with the signature g(x, z, y) which will act as wrapper function around f and will forward the arguments accordingly. By shifting all the placeheld arguments to the right, we can just bind g repeatedly.

I think that would work. Is it a good implementation? Maybe. I had fun learning that you can exploit arguments like never before.

Edit: This is an incredibly naive implementation though. Very straight-forward. Not well-tested.

andretshurotshka
@goodmind
May 27 2016 11:46
How to make this works with non-existent keys?
evolve({
    chat_id: defaultTo(path(['message', 'chat', 'id'], update)),
    reply_to_message_id: defaultTo(path(['message', 'message_id'], update)),
    text: defaultTo('Null-catch: no text provided'),
    reply_markup: JSON.stringify
  }, options)
Raine Virta
@raine
May 27 2016 11:48
you could make a version of evolve that handles them
Brad Compton (he/him)
@Bradcomp
May 27 2016 15:13
Or , alternately, compose with a pickAll to always ensure the keys exist.
R.pickAll
Chet Harrison
@ChetHarrison
May 27 2016 16:11
@joneshf ping
Lewis
@6ewis
May 27 2016 16:14
pong
Chet Harrison
@ChetHarrison
May 27 2016 16:15
:smile:
Lewis
@6ewis
May 27 2016 18:34
If I load up two css files - file1. contains .input-calendar {} file2. also contains .input-calendar {}, then I use gulp to bundle it, which .inpu-calendar takes precedence?
LeonineKing1199
@LeonineKing1199
May 27 2016 19:45

There's a typo in that example. It should be this:

R.tryCatch(R.prop('x'), R.F)({x: true}); //=> true

Edit: Here's the fixed version for both:

R.tryCatch(R.prop('x'), R.F)({x: true}); //=> true
R.tryCatch(R.prop('x'), R.F)(null);      //=> false
It takes two functions and returns a function
LeonineKing1199
@LeonineKing1199
May 27 2016 19:57
Actually, I now have a question about tryCatch. Is the exception forwarded the catcher? Just reading the function description, it doesn't mention.
I'd love to design a catcher that logs the message and the stack trace before bubbling the exception back up again.
Brad Compton (he/him)
@Bradcomp
May 27 2016 20:04
LeonineKing1199
@LeonineKing1199
May 27 2016 20:08
Yay!
Tobias Pflug
@gilligan
May 27 2016 20:10
that typo is actually in the ramda documentation
will try to remember to do a PR later
LeonineKing1199
@LeonineKing1199
May 27 2016 20:11

Yeah, I kind of noticed that. As with all projects on github, we must now mercilessly git-blame whoever did it.

Lol jk, the real important thing is that it's patched before more people are confused.

It also makes me wonder if REPL examples are run through a test suite before being published.

Tobias Pflug
@gilligan
May 27 2016 20:14
should use doctests like @davidchambers added for sanctuary
LeonineKing1199
@LeonineKing1199
May 27 2016 20:18
I told myself I wouldn't actually play git blame but it was @buzzdecafe!!!!!!
LeonineKing1199
@LeonineKing1199
May 27 2016 20:24
Sick avatar though.
Scott Sauyet
@CrossEye
May 27 2016 23:32
Just remember that most of our docs were written before we tried anything to automatically run them. Some of them were sketches, that were never meant to run, some involved dependencies that would never be met in a REPL. We're cleaning that up, but there's always history.
Scott Sauyet
@CrossEye
May 27 2016 23:41

@LeonineKing1199: To me the sine qua non of currying is described by

const total = reduce(add, 0, values);  // :: Number
const sum = reduce(add, 0); // :: [Number] -> Number

The point of currying to my mind is that starting with a function that takes n parameters, we get a function that we can call with kparameters (k < n) and returns one that expects the remaining n - k of them.

It would seem very strange to me to break the ability to simply call my function with its arguments, but that does seem to be the only way to deal with variadic ones. Either you do this, and call something else (bind) before finally calling the function, or you call it multiple times with values before finally calling it with no values in order to actually invoke it. Neither seems palatable to me, as I don't want to work that way, but I think you have found the one suggestion that might actually work.