These are chat archives for ramda/ramda

16th
Oct 2016
LeonineKing1199
@LeonineKing1199
Oct 16 2016 18:23

Even with currying, I would expect the type signature to be:

(a -> b -> c -> ... -> z) -> y -> x -> w -> ... -> a -> z`

I also see reversing the entire signature to be more useful than simply flipping the first two arguments. But what would be even better is an algorithm that would allow you to manually specify the argument mapping itself. I'm not sure what an intuitive or easy-to-read syntax for that would be but it would be the "ultimate" solution to this type of problem, imo.

Why does it make more sense to use (a -> b -> ... -> z) -> b -> a -> c -> ...-> z?

LeonineKing1199
@LeonineKing1199
Oct 16 2016 19:00
This was a lightly tested implementation:
var flip = function(f) {
  return function() { console.log(arguments); return f.apply(null, Array.from(arguments).reverse()); };
}

var f = (x, y, z) => Array.of(x).concat(y).concat(z).join(', ');

f(0, 1, 2);           // "0, 1, 2"
flip(f)(0, 1, 2); // "2, 1, 0"
Denis Stoyanov
@xgrommx
Oct 16 2016 19:27
@LeonineKing1199 const flip = f => (...args) => f(...args.reverse())
LeonineKing1199
@LeonineKing1199
Oct 16 2016 21:36

:plus1:

I wish this was Slack so I could add a reaction directly to your post lol XD

My fancy ES6 feature-fu is weak. Holding off for the LTS release which is right around the corner too :)