     raise Enum.EmptyError
   end
 
-  def max_by(enumerable, fun) do
+  def max_by(enumerable, fun) when is_function(fun, 1) do
     result =
       reduce(enumerable, :first, fn
         entry, {_, fun_max} = old ->


  """
  @spec chunk_by(t, (element -> any)) :: [list]
  def chunk_by(enumerable, fun) do
    {acc, res} = reduce(enumerable, {[], nil}, R.chunk_by(fun))

    case res do


  """
  @spec take_while(t, (element -> as_boolean(term))) :: list
  def take_while(enumerable, fun) when is_list(enumerable) and is_function(fun, 1) do
    do_take_while(enumerable, fun, [])
  end

  def take_while(enumerable, fun) when is_function(fun, 1) do
    {_, res} =
      Enumerable.reduce(enumerable, {:cont, []}, fn(entry, acc) ->
        if fun.(entry) do
