Is it possible to constrain a List guaranteeing th...
# announcements
j
Is it possible to constrain a List guaranteeing that it always contains at least one element? Currently I use
require
in
init
of the class it's in, but the compiler doesn't know that this invariant exists so still requires null-safety checks.
k
I don't think that's possible unfortunately.
a
What null-safety check are you refering to?
s
build your own list-type, that needs at least one element in the constructor
g
For example of such non empty list implementation you can take a look on NonEmptyList from Arrow https://github.com/arrow-kt/arrow/blob/master/modules/core/arrow-data/src/main/kotlin/arrow/data/NonEmptyList.kt