Joy of Elixir

7. Part 2: Recap

Elixir would be pretty hard to do if you had to write all the code for your programs by yourself. We have already seen that if you want to add, subtract, multiply or divide numbers, Elixir has your back:

iex> 2 + 4
6
iex> 3 - 6
-3
iex> 4 * 12345
49380
iex> 1234 / 4
308.5

We also saw that it can run code inside of some other code, through string interpolation:

iex> place = "World"
iex> "Hello #{place}!"
"Hello, World!"

We saw that it can handle lists:

iex> ["chicken", "beef", "and so on"]
["chicken", "beef", "and so on"]

And it can also handle maps:

iex> person = %{name: "Izzy", age: "30ish", gender: "Female"}

We also saw that it could remember functions for us:

iex> greeting = fn (name) -> "Hello, #{name}!" end
#Function<6.52032458/1 in :erl_eval.expr/5>

And in the last chapter we saw that we could do pattern matching:

iex> %{name: name, age: age} = %{name: "Izzy", age: "30ish"}
%{name: "Izzy", age: "30ish"}
iex> name
"Izzy"
iex> age
"30ish"

But what if I told you that it could do more than this simple math, string interpolation, remembering functions and pattern matching? What if I told you that Elixir already provided some functions that used all of the above things to aid you in building your programs if only you had asked to use them?

Well, all you need to do is ask and Elixir will provide.