Is there a way to flag a collection as non-empty t...
# announcements
j
Is there a way to flag a collection as non-empty to the compiler in the same way you can flag a variable as non-null - or has it already been considered/proposed?
y
Not really currently at least, but check out
NonEmptyList
from #C5UPMM0A0
🙏 1
b
You can also include invariants in your code at proper places. For example, after the line where you certainly expect the collection to be non-empty, write something like:
check(myList.size > 0) {"The previous command should have put at least one element in"}
🙏 1
j
Ha, I had forgotten all about this enquiry, thanks for posting @ianbrandt!
👍 1