View Source Fast.Map (Fast v0.8.1)

Link to this section Summary

Functions

Like Enum.map/2, but takes a map as the first arg instead of a list, and a path of keys down to the list to which the mapping func should be applied.

Link to this section Functions

Link to this function

deep_map(tree, list, func)

View Source
@spec deep_map(map(), nonempty_maybe_improper_list(), (... -> any())) :: map()

Like Enum.map/2, but takes a map as the first arg instead of a list, and a path of keys down to the list to which the mapping func should be applied.

example

Example:

data = %{
  "groups" => [
    %{
      "elements" => [
        %{"type" => "text"}
      ]
    }
  ]
}

# Updates all the elements in the data
Fast.Map.deep_map(data, ["groups", "elements"], fn element ->
  element
  |> Map.put("kind", element["kind"])
  |> Map.delete("type")
end)