...

/

Controlling the Flow of Impure Functions

Controlling the Flow of Impure Functions

Learn to handle the results of impure functions.

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:

Access this course and 1400+ top-rated courses and projects.