ramda icon indicating copy to clipboard operation
ramda copied to clipboard

Inconsistent behaviour of `pathOr` and `propOr`

Open bzums opened this issue 8 years ago • 2 comments

Hey all, I am puzzled because of the output of the following snippet:

console.log(R.pathOr({}, ['some'], { some: undefined }) === undefined) // false
console.log(R.pathOr({}, ['some'], {}) === undefined) // false
console.log(R.propOr({}, 'some', { some: undefined }) === undefined) // true
console.log(R.propOr({}, 'some', {}) === undefined) // false

I found this confusing and had a look at the implementation which confused me more since propOr just proxies the call to pathOr: https://github.com/ramda/ramda/blob/master/source/propOr.js#L32 => how can the behaviour be different?

Furthermore, the documentation says:

If the given, non-null object has an own property with the specified name, returns the value of that property.

The wording "has own property" leads imo to the understanding that hasOwnProperty is actually used in the implementation. Imo that would also explain the behaviour from above since:

Object.hasOwnProperty.call({ test: undefined }, 'test'); // true

What am I missing here and could the documentation be more explicit in some way?

Update: I had a look at the test cases: https://github.com/ramda/ramda/blob/master/test/propOr.js#L27 this test seems to contradict with the code snippet, am I right?

bzums avatar Aug 27 '18 09:08 bzums

We simply have not had a release since that was fixed. It should work soon.

CrossEye avatar Aug 30 '18 22:08 CrossEye

Perfect, will close this one then.

bzums avatar Sep 03 '18 09:09 bzums