Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path should return entire object for empty path #979

Merged
merged 1 commit into from
Mar 30, 2015
Merged

Path should return entire object for empty path #979

merged 1 commit into from
Mar 30, 2015

Conversation

paldepind
Copy link
Member

Today _.path([], someObj) returns undefined. This seems inconsistent to me. If you take zero steps down, you're still at the top.

This modifies the internal _path function so that _.path([], obj) returns the passed in object and so that _.pathEq([], obj, obj) === true.

This PR simply removes a special case in the code. This, I think, goes to show that the current behavior is inconsistent, i.e. it is not how a user would guess the function would be working.

If the current behavior was implemented with a good reason I'm sorry for this PR :)

@buzzdecafe
Copy link
Member

makes sense.

🐄

@CrossEye
Copy link
Member

🌿

@@ -5,7 +5,7 @@ var R = require('..');

describe('path', function() {
var deepObject = {a: {b: {c: 'c'}}, falseVal: false, nullVal: null, undefinedVal: undefined, arrayVal: ['arr']};
it('takes a path and an object and returns the value at the path or undefined', function() {
it('takes a path and an object and returns the value at the path or the object', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wording change should be reverted. Your argument is that the object is the value at the path when the path is []. Also, the function does still return undefined if the path does not exist.

@paldepind
Copy link
Member Author

You're right David. I didn't think about that when changing the text.

@davidchambers
Copy link
Member

🌳

buzzdecafe added a commit that referenced this pull request Mar 30, 2015
Path should return entire object for empty path
@buzzdecafe buzzdecafe merged commit 8f38c9b into ramda:master Mar 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants