REnum.Support (REnum v0.8.0)
Summarized other useful functions related to enumerable.
Defines all of here functions when use REnum.Support
.
Link to this section Summary
Functions
Returns the first element for which function(with each element index) returns a truthy value.
Returns true if argument is list and not keyword list.
Returns true if argument is map and not range.
Returns matching function required one argument by given pattern.
Returns true if argument is range.
Returns truthy count.
Returns truthy count that judged by given function.
Link to this section Types
type_enumerable()
Specs
type_enumerable() :: Enumerable.t()
type_pattern()
Specs
Link to this section Functions
find_index_with_index(enumerable, func)
Specs
find_index_with_index(type_enumerable(), function()) :: neg_integer() | nil
Returns the first element for which function(with each element index) returns a truthy value.
Examples
iex> REnum.find_index_with_index(1..3, fn el, index ->
...> IO.inspect(index)
...> el == 2
...> end)
# 0
# 1
1
list_and_not_keyword?(enumerable)
Specs
list_and_not_keyword?(type_enumerable()) :: boolean()
Returns true if argument is list and not keyword list.
Examples
iex> REnum.list_and_not_keyword?([1, 2, 3])
true
iex> REnum.list_and_not_keyword?([a: 1, b: 2])
false
map_and_not_range?(enumerable)
Specs
map_and_not_range?(type_enumerable()) :: boolean()
Returns true if argument is map and not range.
Examples
iex> REnum.map_and_not_range?(%{})
true
iex> REnum.map_and_not_range?(1..3)
false
match_function(pattern)
Specs
match_function(type_pattern()) :: function()
Returns matching function required one argument by given pattern.
Examples
iex> REnum.match_function(1..3).(2)
true
iex> REnum.match_function(~r/a/).("bcd")
false
range?(arg1)
Specs
range?(type_enumerable()) :: boolean()
Returns true if argument is range.
Examples
iex> REnum.range?([1, 2, 3])
false
iex> REnum.range?(2..3)
true
truthy_count(enumerable)
Specs
truthy_count(type_enumerable()) :: non_neg_integer()
Returns truthy count.
Examples
iex> REnum.truthy_count([1, 2, 3])
3
iex> REnum.truthy_count([1, nil, false])
1
truthy_count(enumerable, func)
Specs
truthy_count(type_enumerable(), function()) :: non_neg_integer()
Returns truthy count that judged by given function.
Examples
iex> REnum.truthy_count([1, 2, 3], &(&1 < 3))
2
iex> REnum.truthy_count([1, nil, false], &(is_nil(&1)))
1
iex> REnum.truthy_count(["bar", "baz", "foo"], ~r/a/)
2