Replies: 2 comments 1 reply
-
...similar to the newish modifyPath behaviour (which I've only just noticed exists), but interested to see if there is a lens-like way to do this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Maybe something like this is what you're looking for const fn = x => x === undefined ? x : "bar";
const notNil = complement(isNil); // just an example predicate
const overWhen = curry((pred, lp, fn, obj) =>
when(
pipe(view(lp), pred), // passing the value from view to the predicate
over(lp, fn) // does the "over" when the value passes the predicate
)(obj)
)
const overWhenExists = overWhen(notNil) // for your specific request
overWhenExists(lensPath(["foo"]), fn, {}); // {} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Can anyone point me in the right direction here?
In other words, if the path doesn't exist, I don't want any changes to the object.
I'm guessing this could be done by handling
fn -> undefined
as a special case, or by detecting the path does not exist and never calling fn.Would/could I create a customised
over
orlensPath
?Beta Was this translation helpful? Give feedback.
All reactions