Skip to content

Instantly share code, notes, and snippets.

@KamilLelonek
Created July 5, 2019 13:12
Show Gist options
  • Save KamilLelonek/01d79bc4f42dfab2ab1eaea8ccbc99de to your computer and use it in GitHub Desktop.
Save KamilLelonek/01d79bc4f42dfab2ab1eaea8ccbc99de to your computer and use it in GitHub Desktop.
defmodule List do
def flatten(list, acc \\ [])
def flatten([], acc), do: acc
def flatten([[] | t], acc), do: flatten(t, acc)
def flatten([h | t], acc) when is_list(h), do: flatten(h, flatten(t, acc))
def flatten([h | t], acc), do: [h | flatten(t, acc)]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment