These are chat archives for ramda/ramda

7th
Sep 2015
Raine Virta
@raine
Sep 07 2015 11:04
is it by design that cond can't be called with two arguments directly?
Scott Sauyet
@CrossEye
Sep 07 2015 12:38
@raine: I don't think so, just not considered. It's probably worth a change.
Raine Virta
@raine
Sep 07 2015 12:43

:point_up: August 18, 2015 2:50 PM

by the way @trbrc, I don't think this works because maxBy takes at most two arguments

Scott Sauyet
@CrossEye
Sep 07 2015 14:45
You're right, @raine, we changed these from operating on lists to binary in #1231. This only works by coincidence: The max was in one of the first two positions. One correct answer would be to use a fold:
var largestHead = R.reduce(R.maxBy(R.head), [-Infinity]);
largestHead([[1, 5], [3, 9], [0, 3], [2, 7]]); //=> [3, 9]
Scott Sauyet
@CrossEye
Sep 07 2015 14:54
@raine: The history of cond is a little more convoluted. The original version wouldn't have easily admitted to passing the data. #518 was the original, modified signifcantly in #961.
David Chambers
@davidchambers
Sep 07 2015 16:47

One solution to the Boolean trap is to have descriptive :alien:s for true and false. For example:

const inclusive = true;
const exclusive = false;

// …

R.filter(R.propSatisfies(inRange(exclusive, exclusive, 3, 6), 'length'), xs);

I was pleased to realize that I could define const optional = true; const required = false; in one module so I could write typeCheckProperty('username', required) rather than typeCheckProperty('username', false) or typeCheckProperty('username', {optional: false}).

Scott Sauyet
@CrossEye
Sep 07 2015 16:53
@davidchambers: That helps a lot with the public API, which is probably enough of a reason to do it, but it doesn't prevent inRange(false, true, 3, 6), nor does it solve the implementation issues. (Even here it helps, but since if (leftClusive === inclusive) is really just sugar for if (leftClusive === true), it only goes so far.)
Scott Sauyet
@CrossEye
Sep 07 2015 17:39
@davidchambers (or others who understand lenses well): I just answered a StackOverflow question using several evolve calls. I feel as though there should be some great way to think about this with lenses, but my brain is still not quite working that way. Any suggestions for how to rewrite this with lenses?
David Chambers
@davidchambers
Sep 07 2015 17:40
I’ll have a look. :)
Scott Sauyet
@CrossEye
Sep 07 2015 17:40
thanks
David Chambers
@davidchambers
Sep 07 2015 18:05
Scott Sauyet
@CrossEye
Sep 07 2015 18:12
thanks. Does makeLenses seem useful enough to you to include in Ramda?
David Chambers
@davidchambers
Sep 07 2015 18:38
It does. I would use it often. :)