Enum.min_max_by/3
defmodule Enum do
def min_max(
enumerable,
fun,
empty_fallback \\ fn -> raise(Enum.EmptyError) end
)
end
Returns a tuple with the minimal and the maximal elements in the enumerable as calculated by the given function. If multiple elements are considered maximal or minimal, the first one that was found is returned.
If the enumerable is empty, the provided empty_fallback
is called.
The default empty_fallback
raises Enum.EmptyError
.