View Source Torus (Torus v0.1.0)
Generic utility functions for Elixir.
Summary
Functions
Recursively replaces the value at the given path with the new value. Supports lists, maps, and nested lists and maps.
Functions
Recursively replaces the value at the given path with the new value. Supports lists, maps, and nested lists and maps.
Example
iex> replace_in(%{first_key: [%{second_key: 1}]}, [:first_key, 0, :second_key], 2)
%{first_key: [%{second_key: 2}]}
Or the value can be a function that takes the current value and returns the new value:
iex> replace_in([%{first_key: 2}], [0, :first_key], &Kernel.*(&1, 5))
[%{first_key: 10}]