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.

`propOr`/`pathOr` inconsistency

See original GitHub issue
propOr('bar', 'foo')({ foo: undefined }); // -> undefined
pathOr('bar', ['foo'])({ a: undefined });  // -> 'bar'

Both propOr and pathOr define themselves as returning the value if it is non-null; else the ‘or’ value. These two functions should consistently handle undefined

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
zachlysobeycommented, Aug 22, 2017

Not sure if I should piggy-back on this or open a new issue. I get that it behaves the way the docs say it does, but I am not convinced that this is the right approach.

To restate the issue:

propOr returns the default if it fails a hasOwnValue check, but pathOr returns the default if the path lookup returns a falsy value null, undefined, or NaN. (thanks for the correction @Bradcomp)

I find this to be confusing and inconsistent.

const foo = { bar: null }
R.propOr('hello', 'bar', foo) // null
R.pathOr('hello', ['bar'], foo) // 'hello'

The similarity in the fn names would make you think intuitively that they behave the same way.

Personally, I think I prefer the way this is handled in R.pathOr because it seems more intuitive. Its like using R.path(...) OR (||) the default.

R.path(['bar'], foo) || 'hello' // 'hello'

(Note: its not immediately clear to me how/if this relates to https://github.com/ramda/ramda/issues/1712, apologies if this is a dupe)

2reactions
CrossEyecommented, Nov 15, 2018

@nfantone: I’m going to try very hard to get a release out this weekend. That should be part of it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inconsistency effects in source memory and compensatory ...
Results show an inconsistency effect in source memory accompanied by a compensatory schema-consistent guessing bias when expectancy strength is high, that is, ...
Read more >
Your Inconsistency Is More Noticeable Than You Think - Forbes
A study on how your consistency affects​ your performance at work. Your fellow workers are watching you more than you realize.
Read more >
Inconsistency - Logically Fallacious
In terms of a fallacious argument, two or more propositions are asserted that cannot both possibly be true. In a more general sense,...
Read more >
Embracing Inconsistency - Drew Amoroso
We've been taught that inconsistency, and flip-flopping, and making decisions that are inconsistent with one another is a sign of lack of focus, ......
Read more >
Inconsistency Fallacy Logic & Examples - Study.com
Inconsistency fallacy is a statement that is a contradiction. In such cases, the argument or stance is often erroneous or flawed mainly because ......
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