Skip to content

Instantly share code, notes, and snippets.

@dskecse
Last active October 12, 2015 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dskecse/88d93eb9037bf57abc10 to your computer and use it in GitHub Desktop.
Save dskecse/88d93eb9037bf57abc10 to your computer and use it in GitHub Desktop.
defmodule MyEnum do
def all?([head | tail], func \\ fn x -> x end) do
func.(head) && all?(tail, func)
end
def all?([], _), do: true
def each([], _), do: []
def each([head | tail], func) do
[func.(head), each(tail, func)]
end
# TODO: do something with unflatten lists
def filter([], _), do: nil
def filter([head | tail], func) when func.(head) == true do
[head, filter(tail, func)]
end
def filter([head | tail], func) when func.(head) == false do
[filter(tail, func)]
end
def split
def take
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment