Simple project to study and practice Elixir
- No mutable data (no side effect)
- No state (no implicit, hidden state. Functional programming do not eliminate state, it just make it visible and explicit (at least when programmers want it to be).
- Referential transparency: Expressions can be replaced by its values. Example
=
5*5 can be replaced by 25
- Elixir >= 1.6
This project is organized in elixir source files and each example have comments.
elixir types.exs
Mix creates a new Elixir project
cd hello_world
mix test
REPL interaction
iex -S mix
iex(1)> HelloWorld.hello()
Nice tool to create one inicial project, could help to organize projects and already create one test file :)
Turn error cases more explicit
def div(a, 0) do
:no_dice
end
Simplify parameters validation and leaves more explicit
def div(a, 0) do
:no_dice
end
def div(a, b) do
a / b
end
Simplify chained operations
val =
"leo"
|> reverse
|> capitalize
|> reverse
More tutorials here