Proposal for the Option/Maybe datatype

Both T? and Option<T> are actually a sum of two types: T and a single-value type ( null or “Option.EMPTY”).

@broot I see that you actually describe cases where two such types are not enough: you need three. And you propose to solve this by a combination ( a sum) of these two types (or by Option<Option<T>>).
I would call this a naïve implementation of a more complex type.

So I think that instead of introduction into a general usage of another similar type, we better create / use a generic type that naturally has three type values, e.g. NULL | EMPTY | T
This could be implemented in Kotlin as a sealed generic class of three classes… ( I see something similar here: How to get objects in invariant generic sealed classes? )

More on types here: GitHub - hmemcpy/milewski-ctfp-pdf: Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source and in Kotlin: Union types - #27 by damianw

2 Likes