6 Dealing with optional data

In this chapter

  • 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

Representing optional data has always been a problem in computer programs. The concept of optional data is simple. In everyday life, it’s easy to represent the absence of something when this something is stored in a container—whatever it is, it can be represented by an empty container. For example, 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. But representing the absence of data in computer programs is a little ...

Get The Joy of Kotlin 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.