Skip to content

Instantly share code, notes, and snippets.

@daniel-nelson
Last active June 24, 2018 20:19
Show Gist options
  • Save daniel-nelson/f159794685fc860986752a1d3390fc6a to your computer and use it in GitHub Desktop.
Save daniel-nelson/f159794685fc860986752a1d3390fc6a to your computer and use it in GitHub Desktop.
#
# my solution to ListsAndRecursion-6 of Programming Elixir 1.6
#
defmodule MyList do
def flatten([]) do
[]
end
def flatten([head | tail]) when is_list(head) do
flatten(head) ++ flatten(tail)
end
def flatten([head | tail]) do
[head | flatten(tail)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment