update in
update a value in nested data structure
(any xs, list keys, function f) -> any
Given a dict or list of xs
, returns the same type of collection with f(v)
placed at the end of navigating through the list of keys, where v
is the value originally found.
If any intermediate structures have to be created, they will be, depending on key type. String keys create dicts. Long keys create lists.
If a value is placed in a list, any undefined indexes are filled with nil
.
Returns nil
if xs
is nil
.
Throws an error if xs
is neither a dict nor a list.
Throws an error if xs
is a dict or a list and keys is nil
.
Throws an error if f
is nil.
Throws an error if navigating into a list and the key cannot be cast to a long or the key is negative.
Throws an error if navigating into a dict and the key cannot be cast to a string.
Parameters
Name | Type | Description |
---|---|---|
xs |
dict or list | The dict or list to access |
keys |
list | The keys and indexes to traverse |
f |
function |
A function of the form (v) -> any that transforms any existing value to the updated value. |