Controlling the Flow of Impure Functions
Learn to handle the results of impure functions.
We'll cover the following
Shop checkout
The first strategy for handling unexpected events is to control the flow, as we covered in Chapter 4, Using Pattern Matching to Control the Program Flow. We can use conditional structures, like case
, if
, or function clauses to handle impure function results. They are flexible and good for handling simple cases, but not so much for complex ones.
$ iex
iex> c("shop.ex")
iex> Shop.checkout(2)
Quantity?
three
'''Output ->
It's not a number
:ok
'''
Try it below:
Get hands-on with 1400+ tech skills courses.