Enum.min_max/2

defmodule Enum do
  def min_max(
    enumerable,
    empty_fallback \\ fn -> raise(Enum.EmptyError) end
  )
end

Returns a tuple with the minimal and the maximal elements in the enumerable according to Erlang’s term ordering. 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.