These are chat archives for ramda/ramda

5th
Apr 2015
Simon Friis Vindum
@paldepind
Apr 05 2015 06:50
Am I remembering incorrectly or doesn't Ramda has a function that looks a bit like Haskells guards? I can't find it right now.
Simon Friis Vindum
@paldepind
Apr 05 2015 07:03
Finally, I found it: cond
Have considered doing something like case where the eq is uneeded?
var fn = R.case(
  [0,   R.always('water freezes at 0°C')],
  [100, R.always('water boils at 100°C')],
  [R.__, (temp) => 'nothing special happens at ' + temp + '°C']
);
That's abusing the curry placeholder though. But the catch all could also be an array with length 1?
Michael Hurley
@buzzdecafe
Apr 05 2015 10:50
this is really just sugar on cond. you could write that as:
var fn = R.cond(
  [R.eq(0),   R.always('water freezes at 0°C')],
  [R.eq(100), R.always('water boils at 100°C')],
  [R.always(true) => function(temp) { return 'nothing special happens at ' + temp + '°C'; } ]
);
Simon Friis Vindum
@paldepind
Apr 05 2015 10:53
@buzzdecafe Yes. That is what I said. It's like cond but the eq is uneeded.
But I think it is sugar for a quite common case.
Simon Friis Vindum
@paldepind
Apr 05 2015 12:18
And it is similar to JavaScrips switch statement and Haskells case.
Scott Sauyet
@CrossEye
Apr 05 2015 15:37
I don't see any great reason for that sugar, I guess. Having a function in that first position is flexible, and it's fairly simple to wrap .eq around values if that's what's desired. I do somewhat like the idea of the placeholder as a catch-all, but R.T works reasonably well, and could always be aliased if the user desired with otherwise.