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:
fun divide(num: Int, den: Int): Int? { return if (num % den != 0) { null } else { num / den } } fun division(a: Int, b: Int, den: Int): Pair<Int, Int>? { val aDiv = divide(a...