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

Allow to use setIn for deep-nested values #131

Closed
andresmgot opened this issue Oct 25, 2019 · 3 comments · Fixed by armand-janssen/openapi-transformer#45 · May be fixed by nick-invision/private-action#5
Closed

Allow to use setIn for deep-nested values #131

andresmgot opened this issue Oct 25, 2019 · 3 comments · Fixed by armand-janssen/openapi-transformer#45 · May be fixed by nick-invision/private-action#5
Labels
enhancement New feature or request

Comments

@andresmgot
Copy link

Hi!

When using Documents, sometimes I need to set a value which parent node doesn't exists (yet) but that ends up in an error:

> d = yaml.parseDocument("foo: bar")
Document {
...
> d.setIn(["a", "b"], 1)
Error: Expected YAML collection at a. Remaining path: b

The above can be done executing d.setIn(["a"], {b: 1}) but I was thinking that it would be helpful for the method setIn to do that for you, similar to how lodash works:

> a = {b: 1}
{ b: 1 }
> lodash.set(a, "c.d", 2)
{ b: 1, c: { d: 2 } }

Do you think this is something doable? Thanks in advance!

@eemeli eemeli added the enhancement New feature or request label Oct 25, 2019
@eemeli
Copy link
Owner

eemeli commented Oct 25, 2019

That could work. There's a corner case that'll need to be settled with a path like ['foo', 3]: Should the created object be a map or a sequence?

@andresmgot
Copy link
Author

I would say a map? If the intention with ['foo', 3] is to set the fourth element of a sequence that doesn't exists, it wouldn't be logic to fill the rest of the sequence (elements from 0 to 2) with empty values. Is that what you mean?

@eemeli
Copy link
Owner

eemeli commented Feb 10, 2020

Finally got around to implementing this. Went with non-negative integer keys creating sequences + everything else creating maps, as that's what Lodash also does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants