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

modifyPath does not work for empty array path #3340

Open
valerii15298 opened this issue Nov 23, 2022 · 4 comments
Open

modifyPath does not work for empty array path #3340

valerii15298 opened this issue Nov 23, 2022 · 4 comments

Comments

@valerii15298
Copy link

In this case nothing happens:
modifyPath([], append(1), []) => []

But logically modifyPath should apply function for empty array and in result there should be [1] and not []
But actual output is an empty array []

@semmel
Copy link
Contributor

semmel commented Nov 24, 2022

What path would an empty array represent?

This is what works:

modifyPath([0], append(1), [[]]);
// -> [[1]]

@JuanGalilea
Copy link
Contributor

JuanGalilea commented Nov 24, 2022

Shouldn't an empty path point to the supplied object?
Something like this:

modifyPath([], f, a) === f(a)

But the function has a guard fast returning the final argument in case of an empty path

if ((!_isObject(object) && !_isArray(object)) || path.length === 0) {
  return object;
}

Something like this would satisfy what's being asked:

if (!_isObject(object) && !_isArray(object)) {
  return object;
}
if (path.length === 0) {
  return fn(object);
}

I'm not sure if this goes against any of the principles of the library though. Or if its really that useful to support something like this.

@valerii15298
Copy link
Author

@JuanGalilea yep, that is what I meant, thanks.
@CrossEye what do you think?

JuanGalilea added a commit to JuanGalilea/ramda that referenced this issue Apr 21, 2023
JuanGalilea added a commit to JuanGalilea/ramda that referenced this issue Apr 21, 2023
JuanGalilea added a commit to JuanGalilea/ramda that referenced this issue Apr 21, 2023
JuanGalilea added a commit to JuanGalilea/ramda that referenced this issue Apr 21, 2023
@JuanGalilea
Copy link
Contributor

Finally brought myself to open a pull request for this.

Checked all other path functions, all of them already supported this behaviour (except for R.assocPath, but i dont know how would that work ).

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

No branches or pull requests

3 participants