View Source Chord.Utils.Context.MapTransform (Chord v0.2.0)
Utilities for manipulating nested maps, including deep merging.
Summary
Functions
Updates a deeply nested map using another map of updates.
Functions
Updates a deeply nested map using another map of updates.
Parameters
original
(map): The original map to be updated.updates
(map): A map containing the updates to be applied.
Notes
- Preserves the structure of the original map while applying the updates.
- Creates missing keys in the original map if they are present in the updates.
Examples
iex> alias Chord.Utils.Context.MapTransform
iex> original = %{users: %{user_a: %{name: "Alice", age: 30}, user_b: %{name: "Bob", age: 25}}}
iex> updates = %{users: %{user_b: %{age: 26}}}
iex> MapTransform.deep_update(original, updates)
%{users: %{user_a: %{name: "Alice", age: 30}, user_b: %{name: "Bob", age: 26}}}
iex> original = %{}
iex> updates = %{users: %{user_a: %{profile: %{name: "Alice"}}}}
iex> MapTransform.deep_update(original, updates)
%{users: %{user_a: %{profile: %{name: "Alice"}}}}