The option functor

As Tony Hoare once put it, null references were his one billion dollar mistake[3]. Regardless of your background, you will no doubt have encountered versions of the dreadful NullPointerException. This usually happens when we try to call a method on an object reference that is null.

Clojure deals with null values due to its interoperability with Java. In this section we will learn how Clojure provides improved support for dealing with null values.

The core library is packed with functions that do the right thing if passed a nil value (Clojure's version of Java's null). For instance, how many elements are there in a nil sequence? Consider the following code snippet:

(count nil) ;; 0 

Thanks to conscientious design decisions ...

Get Hands-On Reactive Programming with Clojure - Second Edition 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.