question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

R.cond is a mess!

See original GitHub issue

R.cond returns a function, why? It doesn’t make any sense.

What is more primitive, a function that resolves on invocation, or one that always returns a function? I want to simply be able to do this:

    const address = R.cond([
        [email.to && email.to.includes(search), email.to],
        [email.cc && email.cc.includes(search), email.cc],
        [email.bcc && email.bcc.includes(search), email.bcc],
    ]);

It doesn’t work! Because it returns a function.

You’re example in the docs is this:

var fn = R.cond([
  [R.equals(0),   R.always('water freezes at 0°C')],
  [R.equals(100), R.always('water boils at 100°C')],
  [R.T,           temp => 'nothing special happens at ' + temp + '°C']
]);
fn(0); //=> 'water freezes at 0°C'
fn(50); //=> 'nothing special happens at 50°C'
fn(100); //=> 'water boils at 100°C'

However, if you wrote the cond how I’m suggesting, it would look like this, which is even more readable! and it allows cond to work more generally on more use cases:

var fn = (x) => R.cond([
  [x === 0 ,    'water freezes at 0°C'],
  [x === 100, 'water boils at 100°C'],
  [true,           'nothing special happens at ' + x + '°C']
]);
fn(0); //=> 'water freezes at 0°C'
fn(50); //=> 'nothing special happens at 50°C'
fn(100); //=> 'water boils at 100°C'

The way it is right now, how many people actual use cond, probably very few. I would recommend not using it and avoiding it even.

I really like Ramda, but I think you screwed up with this one, thank you.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:25
  • Comments:21 (14 by maintainers)

github_iconTop GitHub Comments

18reactions
davidchamberscommented, Sep 5, 2017

This isn’t about what works for you, it’s about what’s best, period, so let’s please leave out of the discussion these personal sentiments.

This thread contains several unsubstantiated claims which sound to me very much like personal sentiments. For example:

Nested ternaries are a terrible idea though, and I would never want to do that to a poor soul trying to read my code.

It’s clear that you care a great deal about Ramda @decoursin, which is wonderful. Everyone involved in this discussion cares a great deal about Ramda. My suggestion to you is that you consider the tone with which you convey your ideas. I welcome disagreement, but prefer people to disagree with me in a friendly manner. 😃

16reactions
buzzdecafecommented, Aug 29, 2017

i’m good with it

Read more comments on GitHub >

github_iconTop Results From Across the Web

MESS.pdf
Description A mixed collection of useful and semi-useful diverse statistical functions, some of which may even be referenced in. The R Primer book....
Read more >
5 Dealing with messy data | Modern Statistics with R
When variables of different types are somehow combined (with addition, put in the same vector, and so on), R will coerce both to...
Read more >
cleaning a messy character column in R - Stack Overflow
We create a logical condition, i.e. if the length of the index is greater than 0, we return the element corresponding to 'x1'...
Read more >
launch is a mess... : r/DarkTide - Reddit
r /spotted - Insane [Volvo TP21 'Sugga'] spotted in London. ... Power Supply Interruption (lights out) is the best special condition.
Read more >
How to use the R case_when function - Sharp Sight
Inside the parenthesis of case_when, the left hand side is a conditional statement that should evaluate as TRUE or FALSE . This condition...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found