[TOC]
Elixir 101 is a codelab for learning the basics of the Elixir programming language.
Elixir is a functional language with excellent tooling and a growing community, which is a built on top of Erlang and runs on the BEAM VM. It is known for excellent parallelization and process stability and recovery.
Videos to get you warmed up:
- Elixir Documentary (12 min video) A developer focused documentary on Elixir origin story
- Elixir in 9 Minutes (9 min video) Dave Thomas quick into to Elixir (coding example)
- Elixir in 30 Minutes (30 min video) Dave Thomas "longer" into to Elixir (coding example)
Articles for context:
- Goodbye OOP insights about what OOP promised but didn't deliver, and how a functional approach can.
Before coming to the class I recommend that you have a working Elixir install, or Docker runtime, and have downloaded these codelab files.
You have a few options, pick one you're comfortable with.
You can run elixir on a server, for free, via Google Cloud Platform Shell or on any remote server on which you can install Elixir.
$ sudo apt-get update; sudo apt-get install elixir -y
You can install elixir on your local machine.
It has easy install methods for most *nix and osx and even windows.
If you have docker, you can simply run elixir inside of docker, no install needed.
An example of running via docker:
# grab elixir
$ docker pull elixir
# get into bash, inside the container
$ docker run -it --rm elixir bash
# get into iex, with PWD mapped to /app and setup as the working directory
$ docker run -it --rm --name ex101 -v "$PWD":/app -v "$(pwd)/_tmp/.mix":/root/.mix -w /app elixir iex
If you decide to use docker, you can setup an
alias
in the .bashrc
to run elixir commands inside docker, like so:
# paste the following into .bashrc or .profile or whatever
elixir() {
docker run -it --rm --name ex101 -v "$(pwd)":/app -w /app elixir "$@"
}
iex() {
docker run -it --rm --name ex101 -v "$(pwd)":/app -w /app elixir iex "$@"
}
After installation, you will have three new executables: iex
, elixir
and elixirc
-
Check installed version
$ elixir --version
-
Launch
iex
the Elixir REPL and do a hello world$ iex Erlang/OTP 20 [erts-9.3.3.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false] Interactive Elixir (1.6.6) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> IO.puts "hello world" hello world :ok
The codelab files are available from github.
git clone https://github.com/zeroasterisk/elixir-101-codelab.git
cd elixir-101-codelab
Alternatively, you can download as a zip file.
The following will run tests in each of the sub-project folders inside this repo.
cd elixir-101-codelab
find . -maxdepth 1 -type d \( ! -name . \) \( ! -name .git \) -exec bash \
-c "cd '{}' && docker run -it --rm --name e1 -v "$PWD":/app -w /app mix test" \;
If all the tests pass then you are good to go.
If some of the tests fail I would appreciate if you send details to alanblount@google.com.
The codelab is split into sub-projects, and instructions are in the README in each folder, as well as in files.
Simply start from the top and fix the code as you go, and watch tests turn green.