Utility.Collections (Portico/Z v0.1.0)

Special utilities that we use for collections (maps, lists, etc.)

Link to this section Summary

Functions

Convert a map with string keys into atom keys.

Combine two lists into one list of tuple combinations

Convert a map with atom keys into string keys.

Convert a list of String to a hashtag string

Link to this section Functions

Link to this function

atomify_keys(map)

Specs

atomify_keys(map()) :: map()

Convert a map with string keys into atom keys.

NOTE: Maps with neither string nor atom keys will behave weirdly.

Examples

iex> Utility.Collections.atomify_keys(%{"a" => "b", "c" => "d"})
%{a: "b", c: "d"}
Link to this function

combine(left, right)

Specs

combine(left :: list(), right :: list()) :: list()

Combine two lists into one list of tuple combinations

Examples

iex> Utility.Collections.combine(~W{a b}, ~W{1 2})
[{"a", "1"}, {"a", "2"}, {"b", "1"}, {"b", "2"}]
Link to this function

stringify_keys(map)

Specs

stringify_keys(map()) :: map()

Convert a map with atom keys into string keys.

NOTE: Maps with neither string nor atom keys will behave weirdly.

Examples

iex> Utility.Collections.stringify_keys(%{a: "b", c: "d"})
%{"a" => "b", "c" => "d"}
Link to this function

to_hashtags(list)

Specs

to_hashtags([String.t()]) :: String.t()

Convert a list of String to a hashtag string

See Utility.Text.parse_hashtags/1 for details.

Examples

iex> ["GreatWall", "China", "BorderPolicy"]
...> |> Utility.Collections.to_hashtags()
"#GreatWall #China #BorderPolicy"

iex> Utility.Collections.to_hashtags "#Popsicle"
"#Popsicle"

iex> Utility.Collections.to_hashtags 42
""