February 2018
Beginner
200 pages
4h 37m
English
Elixir’s special form with permits you to combine multiple matching clauses. If all clauses match, the code executes and returns the do block result. If one clause doesn’t match, the code stops and returns the value of the non-matching clause. It’s useful to combine clauses that can result in unexpected values. Then you can handle the error at a convenient point, reducing the conditional code for each error. You should use with when you have function pipelines that can result in an error. We’ll use with in the dungeon crawl application, but first let’s try it in a simple example:
| | def checkout() do |
| | result = |
| | with {quantity, _} <- ask_number("Quantity?"), |
| | {price, _} <- ask_number( ... |
Read now
Unlock full access