swiss v2.2.1 Swiss.Enum View Source

Link to this section Summary

Functions

Finds the first element in enumerable where its key equals value.

Applies cb to all elements in enum, ignores the return and returns enum.

Link to this section Functions

Link to this function

find_by(enumerable, default \\ nil, key, value)

View Source

Finds the first element in enumerable where its key equals value.

Examples

iex> Swiss.Enum.find_by([%{life: 11}, %{life: 42}], :life, 42)
%{life: 42}

iex> Swiss.Enum.find_by([%{life: 11}, %{life: 42}], :wat, 42)
nil

iex> Swiss.Enum.find_by([%{life: 11}, %{life: 42}], 42, :wat, 42)
42

iex> Swiss.Enum.find_by([%Swiss.TestStruct{life: 42}], :life, 42)
%Swiss.TestStruct{life: 42}

Applies cb to all elements in enum, ignores the return and returns enum.

Examples

iex> Swiss.Enum.thru([1, 2, 3], fn a -> a + 1 end)
[1, 2, 3]