Implement a simple version of flatten

This commit is contained in:
Nathan Mattes 2021-09-16 17:00:38 +02:00
parent 1be7896f19
commit a52453ed54
1 changed files with 17 additions and 0 deletions

View File

@ -45,6 +45,23 @@ defmodule MyEnum do
end
end
# I gave up on these two.
# split
# take
end
defmodule MyList do
def flatten([]) do
[]
end
def flatten([head|tail]) do
# this is basically the recursion
flatten(head) ++ flatten(tail)
end
def flatten(head) do
# if there's only on element, we make a list out of it, so that we can concat them
[head]
end
end