Skip to content

Latest commit

 

History

History
24 lines (17 loc) · 947 Bytes

optional-types.md

File metadata and controls

24 lines (17 loc) · 947 Bytes

Optionals

Optionals encode the presence or absence of a value in its type.

An optional says:

  • There is a value, and it equals x, or
  • There isn’t a value at all

In languages without the option type, every type can be nullable, with null hanging around every corner waiting to jump out at you. With optionals, we can not only identify to the reader where null might pop up, but we can use option unwrapping to properly handle such cases.

Further reading