Building functional projects
We have a lot in our proverbial tool belt so far and we are adding more. Let's take a look at some more examples where we solve some relatively simple problems using Elixir. This time, however, let's use mix
as well.
Flatten
We will start small, by creating a function to flatten arbitrarily deep, nested lists.
Let's create a project for it using mix new flatten
:
$ mix new reverse * creating README.md * creating .gitignore * creating mix.exs * creating config * creating config/config.exs * creating lib * creating lib/flatten.ex * creating test * creating test/test_helper.exs * creating test/flatten_test.exs Your mix project was created successfully. You can use mix to compile it, test it, and more: cd flatten mix test Run mix help for more commands.
Now, in the lib/flatten.ex
file, let's create the flatten function.
Open the file in your favorite editor and add the following flatten/1
function:
defmodule Flatten do def flatten([]), do: [] def flatten...