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

      3

  """
  def reduce_while(enumerable, acc, fun) do
    Enumerable.reduce(enumerable, {:cont, acc}, fun) |> elem(1)
  end



  """
  @spec filter(t, (element -> as_boolean(term))) :: list
  def filter(enumerable, fun) when is_list(enumerable) and is_function(fun, 1) do
    for item <- enumerable, fun.(item), do: item
  end

  def filter(enumerable, fun) when is_function(fun, 1) do
    reduce(enumerable, [], R.filter(fun)) |> :lists.reverse
  end

