Enum.max_by/4
defmodule Enum do
def max_by(
enumerable,
fun,
sorter \\ &>=/2,
empty_fallback \\ fn -> raise(Enum.EmptyError) end)
)
end
Returns the maximal element in the enumerable as calculated by the given fun
.
By default, the comparison is done with the >=
sorter function. If multiple elements are considered maximal, 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
.