Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created June 15, 2016 08:05
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 JoshCheek/460d79388a72f15bf96e4d6df1b007d6 to your computer and use it in GitHub Desktop.
Save JoshCheek/460d79388a72f15bf96e4d6df1b007d6 to your computer and use it in GitHub Desktop.
Playing with elixir
defmodule MyList do
def flatten([]), do: []
def flatten([head|tail]), do: concat (flatten head), (flatten tail)
def flatten(other), do: [other]
def concat([], list), do: list
def concat([head|tail], list), do: [head|(concat tail, list)]
def reverse(list), do: reverse list, []
def reverse([], reversed), do: reversed
def reverse([head|tail], reversed), do: reverse tail, [head|reversed]
end
IO.inspect MyList.reverse MyList.flatten [1,[2,3,[[[4],5],6],7,[8]],9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment