Warpath.update
You're seeing just the function
update
, go back to Warpath module for more information.
Specs
Updates a nested data structure via the given selector
.
The fun
will be called for each item discovered under the given selector
, the fun
result will be used to update the data structure.
If the selector does not evaluate anything, it returns the data structure unchanged.
This function rely on
Access
behaviour, that means structs must implement that behaviour to got support.
Examples
iex> users = %{"john" => %{"age" => 27}, "meg" => %{"age" => 23}}
...> Warpath.update(users, "$.john.age", &(&1 + 1))
{:ok, %{"john" => %{"age" => 28}, "meg" => %{"age" => 23}}}
iex> numbers = %{"numbers" => [20, 3, 50, 6, 7]}
...> Warpath.update(numbers, "$.numbers[?(@ < 10)]", &(&1 * 2))
{:ok, %{"numbers" => [20, 6, 50, 12, 14]}}
iex> users = %{"john" => %{"age" => 27}, "meg" => %{"age" => 23}}
...> Warpath.update(users, "$.theo.age", &(&1 + 1))
{:ok, %{"john" => %{"age" => 27}, "meg" => %{"age" => 23}}} # Unchanaged