chaperon v0.3.1 Chaperon.Util View Source

Helper functions used throughout Chaperon's codebase.

Link to this section Summary

Functions

Returns last amount elements in a given Enum as a List.

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]
Link to this function

local_pid?(pid)

View Source
local_pid?(pid()) :: boolean()
Link to this function

map_nested_put(map, k2, v2)

View Source
map_nested_put(map(), any(), any()) :: map()

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}}
Link to this function

map_prefix_value(map, prefix)

View Source
map_prefix_value(map(), any()) :: map()

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

module_name(mod)

View Source
module_name(module() | %{name: String.t()}) :: String.t()
Link to this function

percentile_name(percentile)

View Source
Link to this function

preserve_vals_merge(map1, map2)

View Source
preserve_vals_merge(map(), map()) :: map()
Link to this function

shortened_module_name(mod, max_nesting \\ 2)

View Source
shortened_module_name(module() | map(), non_neg_integer()) :: String.t()