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
Youssef Shoaib [MOD]
04/12/2021, 11:10 AM
Not really currently at least, but check out
NonEmptyList
from #C5UPMM0A0
š 1
b
Byron Katz
04/12/2021, 12:55 PM
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"}