Skip to content

Add unsetPath helper function#323

Merged
evilsoft merged 2 commits into
masterfrom
feature/unsetPath
Oct 9, 2018
Merged

Add unsetPath helper function#323
evilsoft merged 2 commits into
masterfrom
feature/unsetPath

Conversation

@evilsoft

@evilsoft evilsoft commented Oct 7, 2018

Copy link
Copy Markdown
Owner

A path a little less traveled

image

This PR adds a function that provides the functionality from the dissocPath function provided by ramda. This was motivated by the documentation on the meiosis project from @foxdonut.

This PR signals a change to some of the existing functions to match this new naming convention for dealing with functions like: prop and propPath. The following functions will be addressed in the next breaking change release, although they will be deprecated and their original names will still be available until we hit 1.0.0:

  • Maybe/propPath -> Maybe/getPath
  • Maybe/prop -> Maybe/getProp
  • helpers/assoc -> helpers/setProp (will work with Array as well)
  • helpers/dissoc -> helpers/unsetProp (will work with Array as well)
  • helpers/propOr -> helpers/getPropOr
  • helpers/propPathOr -> helpers/getPathOr

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 4420ec3 on feature/unsetPath into 2de9adc on master.

@karthikiyengar karthikiyengar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM otherwise.

Used to remove a property or index on a deeply nested `Object`/`Array`.
`unsetPath` is will return a new instance with the property or index removed.

The provided path can be a mixture of either `Integer`s or `String`s to allow

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like we've taken a different direction from Ramda here?

dissocPath([1], { 1: {} } ) // []
unsetPath([1], { 1: {} } ) // { '1': {} }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yeppers, this is by design.
Notice how ramda takes an object and transforms it into an Array, that seemed odd to me.
So unsetPath does nothing to the Object, because Strings are used as props on an Object and it cannot find an Integer key on the Object.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

But this is intentional behavior.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Makes sense. Thanks for the explanation.

@evilsoft

evilsoft commented Oct 9, 2018

Copy link
Copy Markdown
Owner Author

image

@evilsoft
evilsoft merged commit 45b37ac into master Oct 9, 2018
@evilsoft
evilsoft deleted the feature/unsetPath branch October 9, 2018 21:38
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.

3 participants