chaperon v0.3.1 Chaperon.Util View Source
Helper functions used throughout Chaperon
's codebase.
Link to this section Summary
Functions
Inserts a given key-value pair ({k2, v2}
under any values within map
that
are also maps).
Converts a map's values to be prefixed (put in a tuple as the first element).
Link to this section Functions
Returns last amount
elements in a given Enum
as a List
.
Example
iex> alias Chaperon.Util
iex> [] |> Util.last(1)
[]
iex> [1] |> Util.last(1)
[1]
iex> [1,2,3,4] |> Util.last(1)
[4]
iex> [1,2,3,4] |> Util.last(2)
[3,4]
iex> [1,2,3,4] |> Util.last(3)
[2,3,4]
iex> [1,2,3,4] |> Util.last(4)
[1,2,3,4]
iex> [1,2,3,4] |> Util.last(5)
[1,2,3,4]
Inserts a given key-value pair ({k2, v2}
under any values within map
that
are also maps).
Example
iex> m = %{a: 1, b: %{baz: 3}, c: %{foo: 1, bar: 2}}
iex> Chaperon.Util.map_nested_put(m, :baz, 10)
%{a: 1, b: %{baz: 10}, c: %{foo: 1, bar: 2, baz: 10}}
iex> Chaperon.Util.map_nested_put(m, :foo, "ok")
%{a: 1, b: %{baz: 3, foo: "ok"}, c: %{foo: "ok", bar: 2}}
Converts a map's values to be prefixed (put in a tuple as the first element).
Examples
iex> Chaperon.Util.map_prefix_value(%{foo: 1, bar: 2}, :wat)
%{foo: {:wat, 1}, bar: {:wat, 2}}
Link to this function
shortened_module_name(mod, max_nesting \\ 2)
View Sourceshortened_module_name(module() | map(), non_neg_integer()) :: String.t()