May 2018
Intermediate to advanced
412 pages
9h 3m
English
The do…end block is one way of grouping expressions and passing them to other code. They are used in module and named function definitions, control structures…any place in Elixir where code needs to be handled as an entity.
However, do…end is not actually the underlying syntax. The actual syntax looks like this:
| | def double(n), do: n * 2 |
You can pass multiple lines to do: by grouping them with parentheses.
| | def greet(greeting, name), do: ( |
| | IO.puts greeting |
| | IO.puts "How're you doing, #{name}?" |
| | ) |
The do…end form is just a lump of syntactic sugar—during compilation it is turned into the do: form. (And the do: form itself is nothing special; it is simply a term in a keyword list.) Typically ...
Read now
Unlock full access