Chapter 6. Dealing with optional data

This chapter covers

  • The null reference, or “the billion-dollar mistake”
  • Alternatives to null references
  • Developing an Option data type for optional data
  • Applying functions to optional values
  • Composing optional values
  • Option use cases

Representing optional data in computer programs has always been a problem. The concept of optional data is very simple in everyday life. Representing the absence of something when this something is contained in a container is easy—whatever it is, it can be represented by an empty container. An absence of apples can be represented by an empty apple basket. The absence of gasoline in a car can be visualized as an empty gas tank.

Representing the absence of data in computer ...

Get Functional Programming in Java: How functional techniques improve your Java programs now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.