View Source Moar.Enum (Moar v1.27.0)

Enum-related functions.

Link to this section Summary

Functions

Like Enum.at/3 but raises if index is out of bounds.

Removes nil elements from enum.

Returns the first item of enum, or raises if it is empty.

Returns true if the value is a map or a keyword list.

Sorts enum case-insensitively. Uses Enum.sort_by/3 under the hood.

Sorts enum case-insensitively by mapper function. Uses Enum.sort_by/3 under the hood.

Returns a list of elements at the given indices. If :all is given instead of a list of indices, the entire enum is returned.

Returns :tid fields from enumerable.

Link to this section Functions

Link to this function

at!(enum, index, default \\ nil)

View Source
@spec at!(Enum.t(), integer() | [integer()], any()) :: any()

Like Enum.at/3 but raises if index is out of bounds.

@spec compact(Enum.t()) :: Enum.t()

Removes nil elements from enum.

@spec first!(Enum.t()) :: any()

Returns the first item of enum, or raises if it is empty.

Link to this function

is_map_or_keyword(value)

View Source
@spec is_map_or_keyword(any()) :: boolean()

Returns true if the value is a map or a keyword list.

This cannot be used as a guard because it uses Keyword.keyword? under the hood. Also, because of that, it might scan an entire list to see if it's a keyword list, so it might be expensive.

@spec isort(Enum.t()) :: Enum.t()

Sorts enum case-insensitively. Uses Enum.sort_by/3 under the hood.

@spec isort_by(Enum.t(), (any() -> any())) :: Enum.t()

Sorts enum case-insensitively by mapper function. Uses Enum.sort_by/3 under the hood.

@spec take_at(Enum.t(), integer() | [integer()] | :all) :: any()

Returns a list of elements at the given indices. If :all is given instead of a list of indices, the entire enum is returned.

iex> Moar.Enum.take_at(["A", "B", "C"], [0, 2])
["A", "C"]

iex> Moar.Enum.take_at(["A", "B", "C"], :all)
["A", "B", "C"]
@spec tids(Enum.t()) :: list()

Returns :tid fields from enumerable.

This unusual function exists because the authors of Moar use tids (test IDs) extensively in tests.