PassiveSupport.Enum (passive_support v0.8.4)
Functions extending the functionality of enumerables.
Link to this section Summary
Functions
Deep-converts enum
to a list.
Returns true if the given fun
evaluates to false on all
of the items in the enumberable.
Generates a list of all possible permutations of the given enumerable.
Converts an enumerable to a Map
, using the index of
each item as the item's key.
Not to be confused with Enum.map/2, returns a Map
with the key for each
item derived by the return of key_function(item)
or key_function(item, index)
Link to this section Functions
deep_to_list(enum)
Specs
deep_to_list(Enumertable.t(Enumerable.t())) :: [list()]
Deep-converts enum
to a list.
Examples
iex> deep_to_list(%{"game_types" => ["card"], "rulesets_known" => [%{"poker" => "texas hold 'em", "hearts" => true}]})
[{"game_types", ["card"]}, {"rulesets_known", [[{"hearts", true}, {"poker", "texas hold 'em"}]]}]
none?(enum, fun \\ & &1)
Specs
none?(Enumerable.t(), function()) :: boolean()
Returns true if the given fun
evaluates to false on all
of the items in the enumberable.
Iteration stops at the first invocation that returns a
truthy value (not false
or nil
). Invokes an identity
function if one is not provided.
Examples
iex> test_list = [1, 2, 3]
...> none?(test_list, &(&1 == 0))
true
...> none?([0 | test_list], &(&1 == 0))
false
iex> none?([])
true
iex> none?([nil])
true
iex> none?([true])
false
permutations(enum)
Specs
permutations(Enumerable.t()) :: [[any()]]
Generates a list of all possible permutations of the given enumerable.
Examples
iex> permutations(~w"hi ho hey!")
[
["hi", "ho", "hey!"],
["hi", "hey!", "ho"],
["ho", "hi", "hey!"],
["ho", "hey!", "hi"],
["hey!", "hi", "ho"],
["hey!", "ho", "hi"]
]
to_map(enum)
Specs
to_map(Enumerable.t()) :: Map.t()
Converts an enumerable to a Map
, using the index of
each item as the item's key.
Examples
iex> to_map(["hello", "world", "how", "are", "you"])
%{0 => "hello", 1 => "world", 2 => "how", 3 => "are", 4 => "you"}
iex> to_map(["Elixir", "is", "cool"])
%{0 => "Elixir", 1 => "is", 2 => "cool"}
to_map(enum, key_function)
Specs
to_map(Enumerable.t(), function()) :: Map.t()
Not to be confused with Enum.map/2, returns a Map
with the key for each
item derived by the return of key_function(item)
or key_function(item, index)
Examples
iex> to_map(["Elixir", "is", "cool"], &String.reverse/1)
%{"si" => "is", "looc" => "cool", "rixilE" => "Elixir"}
iex> to_map(["hello", "world", "how", "are", "you"], fn (_, index) -> index end)
%{0 => "hello", 1 => "world", 2 => "how", 3 => "are", 4 => "you"}