Elixir Enum Functions Flashcards
Returns a map with keys as unique elements of enumerable and values as the count of every element.
frequencies(enumerable)
Returns true if fun.(element) is truthy for all elements in enumerable.
all?(enumerable, fun \ fn x -> x end)
Returns true if fun.(element) is truthy for at least one element in enumerable.
any?(enumerable, fun \ fn x -> x end)
Finds the element at the given index (zero-based).
at(t(), index(), default()) :: element() | default()
Splits enumerable on every element for which fun returns a new value.
chunk_by(enumerable, fun)
Shortcut to chunk_every(enumerable, count, count).
chunk_every(enumerable, count)
Returns list of lists containing count elements each, where each new chunk starts step elements into the enumerable.
chunk_every(enumerable, count, step, leftover \ [])
Chunks the enumerable with fine grained control when every chunk is emitted.
chunk_while(enumerable, acc, chunk_fun, after_fun)
Turn a list of lists into a single list
concat(enumerables)
Concatenates the enumerable on the right with the enumerable on the left.
concat(left, right)
Returns the size of the enumerable.
count(enumerable)
Returns the count of elements in the enumerable for which fun returns a truthy value.
count(enumerable, fun)
Enumerates the enumerable, returning a list where all consecutive duplicated elements are collapsed to a single element.
dedup(enumerable)
Enumerates the enumerable, returning a list where all elements that return the same value from a function are collapsed to a single element.
dedup_by(enumerable, fun)
Deletes the elements from the start or end of enumerable
drop(enumerable, amount)
Returns a list with every nth element in the enumerable dropped, starting with the first element.
drop_every(enumerable, nth)
Drops elements at the beginning of the enumerable while fun returns a truthy value.
drop_while(enumerable, fun)
Invokes the given fun for each element in the enumerable.
each(enumerable, fun)
Returns true if no elements in enumerable
empty?(enumerable)
Finds the element at the given index (zero-based). and returns {:ok, element} or :error
fetch(enumerable, index)
Finds the element at the given index (zero-based). Raises if index is out of bounds.
fetch!(enumerable, index)
Returns the elements for which a function returns a truthy value
filter(enumerable, fun)
Returns the first element for which fun returns a truthy value. If no such element is found, returns default.
find(enumerable, default \ nil, fun)
Similar to find/3, but returns the index (zero-based) of the element instead of the element itself.
find_index(enumerable, fun)
Similar to find/3, but returns the value of the function invocation instead of the element itself.
find_value(enumerable, default \ nil, fun)
Maps the given fun over enumerable and flattens the result.
flat_map(enumerable, fun)
Maps and reduces an enumerable, flattening the given results (only one level deep).
flat_map_reduce(enumerable, acc, fun)
Returns a map with keys as unique elements of enumerable and values as the count of every element.
frequencies(enumerable)
Returns a map with keys as unique elements given by key_fun and values as the count of every element.
frequencies_by(enumerable, key_fun)
Splits the enumerable into groups based on key_fun.
group_by(enumerable, key_fun, value_fun \ fn x -> x end)