Chapter 7Handling Impure Functions

The world is full of inconsistencies, and the resulting unpredictability is why we have impure functions—functions that can return different values from the same input. If you use a function that expects a number from users, what prevents them from inputting hot dogs? If you have a sign-in form on a website, what will prevent users from submitting the wrong password? If your program fetches data from a database, what guarantees that data is always there? Every program needs to handle errors and unexpected results. It’s the programmer’s job to code a friendly user experience in this wild world of events. While creating code for every uncertain possibility can be boring, working without any strategy will generate ...

Get Learn Functional Programming with Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.