Sure. Besides the reason you've already listed:
-
As a reader of code, I feel that there's a subtle semantic distinction between
Optional<T>
andT
with a.none
case:T.none
: a meaningful element within the domain ofT
; intentionally presentOptional<T>.none
: outside of the domain ofT
; not immediately clear whyOptional<T>
value can be missing (accidental? intentional? the result of bad data? etc.) —Optional
can be pretty overloaded in its meaning
T.none
gives me confidence as a reader that it's a special and intentional value -
Keeping these values within the domain of your type also helps keep your code more intentional on the type. e.g., you can write extensions on
T
instead ofOptional<T>
, hold collections ofT
as opposed toOptional<T>
, etc. Potential for less noise, depending on the specifics of how it's used
From the examples you give, I'd say that I'd prefer Subgroup
have a .none
case than defer to Optional
for it.