Skip to content

Instantly share code, notes, and snippets.

@ronualdo
Last active August 1, 2017 17:52
Show Gist options
  • Save ronualdo/370c9c258cc0c1131fa5ced6b7282878 to your computer and use it in GitHub Desktop.
Save ronualdo/370c9c258cc0c1131fa5ced6b7282878 to your computer and use it in GitHub Desktop.
A small exercise in elixir. Just a function to flatten an array. Tests for this function can be found in https://gist.github.com/ronualdo/66e2339a17a7c33229ca61bda977765e
defmodule Flatten do
def flat(list=[]) do
list
end
def flat([head|tail]) when is_list(head) do
flat(head) ++ flat(tail)
end
def flat([head|tail]) do
[head] ++ flat(tail)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment