Chapter 13
Handling Failures
Functional programming is centered on the use of values, produced and consumed by functions. It is therefore natural, when programming functionally, to treat failures as special values instead of using exceptions. A few standard types are commonly used to represent failures, most notably Option
, Try
(also called Result
), and Either
. These types can be manipulated by higher-order functions to process valid values and to propagate errors or to recover from them. This approach to error handling is particularly well suited to pipelined computations in which catching exceptions is unwieldy because of higher-order functions that embed their own control flow.
13.1 Exceptions and Special Values
A component of a software ...
Get Functional and Concurrent Programming: Core Concepts and Features 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.