gojuno / koptional

Minimalistic Optional type for Kotlin that tries to fit its null-safe type system as smooth as possible.
Apache License 2.0
289 stars 21 forks source link

Remove Any constraint on type parameter? #31

Closed svby closed 6 years ago

svby commented 6 years ago

Currently, the type parameter of Optional is constrained to not be nullable; however, if it weren't, it would allow an important distinction between no value and not present (e.g.: deserializing data).

Would this be possible (or make sense), and would it fit the design goals of this library?

artem-zinnatullin commented 6 years ago

Sorry, this issue totally went under my radar.

I'm afraid we can't make it Optional<Any?>. In Koptional null means None.

By allowing to hold Some(null) we will break a lot of existing use cases as well as functions that we provide:

I'm going to close the issue for now, please feel free to comment, we might reopen it in future :)