Handling Impure Functions with the Error Monad

The Error monad is a data structure that helps you combine functions that can result in an error. It permits you to put functions into a clear sequence, handling the error at a unique point. It helps you reduce conditional codes when functions can have unexpected results. You should use it when your codebase is filled with situations where you must put many functions in sequence and some of them can fail. For example, maybe you have five functions that must be executed in sequence, but some of them are prone to failure.

You may have heard of monads—they are famous in languages with strong and static typing, such as Haskell. Monads have strong mathematical theory, and concepts like functors, applicatives, ...

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.