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

lensing objects: L.merge? #73

Closed
KiaraGrouwstra opened this issue Apr 8, 2017 · 6 comments
Closed

lensing objects: L.merge? #73

KiaraGrouwstra opened this issue Apr 8, 2017 · 6 comments

Comments

@KiaraGrouwstra
Copy link

In the spirit of (batch) upsert, I wonder if, not unlike L.append for updating existing arrays, writing to existing objects might have use for something like L.merge (just a lens equivalent of R.merge).
There might be more, but this just stood out to me as a more likely addition to flesh things out.

@polytypic
Copy link
Member

(Replying with a mobile.) Hmm... Could you give an example of what you have in mind?

@KiaraGrouwstra
Copy link
Author

L.merge(['foo'], { b: 2, c: 3 }, { foo: { a: 1, b: 0 } }); // { foo: { a: 1, b: 2, c: 3 } }

That is to say, I'm imagining an existing object structure to get updated based on the values in the provided object.

@polytypic
Copy link
Member

Hmm... How about this:

L.modify('foo', R.merge(R.__, { b: 2, c: 3 }), { foo: { a: 1, b: 0 } })
// { foo: { a: 1, b: 2, c: 3 } }

@KiaraGrouwstra
Copy link
Author

Well, that works. Thanks! :)

@polytypic
Copy link
Member

With PR #104 one could say:

L.assign('foo', { b: 2, c: 3 }, { foo: { a: 1, b: 0 } })
// { foo: { a: 1, b: 2, c: 3 } }

@KiaraGrouwstra
Copy link
Author

Thanks for the follow-up! That's awesome, looks like object manipulation just got more pleasant. :)

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

2 participants