Fast.Map (Fast v0.11.0)

View Source

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.

Functions

deep_map(tree, list, func)

@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:

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)