 
   """
   @spec filter(t, (element -> as_boolean(term))) :: list
-  def filter(enumerable, fun) when is_list(enumerable) do
+  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) do
+  def filter(enumerable, fun) when is_function(fun, 1) do
     reduce(enumerable, [], R.filter(fun)) |> :lists.reverse
   end
 


  """
  @spec sort(t, (element, element -> boolean)) :: list
  def sort(enumerable, fun) when is_list(enumerable) do
    :lists.sort(fun, enumerable)
  end

  def sort(enumerable, fun) do
    reduce(enumerable, [], &sort_reducer(&1, &2, fun))
    |> sort_terminator(fun)
  end


  """
  @spec partition(t, (element -> any)) :: {list, list}
  def partition(enumerable, fun) when is_function(fun, 1) do
    {acc1, acc2} =
      reduce(enumerable, {[], []}, fn(entry, {acc1, acc2}) ->
        if fun.(entry) do
