Option
The Option<T> datatype is the representation of a presence or absence of a value T. In Arrow, Option<T> is a sealed class with two sub-types, Some<T>, a data class that represents the presence of value T and None, and an object that represents the absence of value. Defined as a sealed class, Option<T> can't have any other sub-types; therefore the compiler can check clauses exhaustively, if both cases, Some<T> and None are covered.
I know (or I pretend to know) what you're thinking at this very moment—why do I need Option<T> to represent the presence or absence of T, if in Kotlin we already have T for presence and T? for absence?
And you are right. But Option provides a lot more value than nullable types, let's jump directly to an example: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access