Jonathan Ellis
05/24/2022, 7:04 PMephemient
05/24/2022, 7:06 PMlast()
throws, size
doesn'tJonathan Ellis
05/24/2022, 7:08 PMephemient
05/24/2022, 7:09 PMisEmpty()
- but lots of parts of Kotlin pre-date the modern style documentYoussef Shoaib [MOD]
05/24/2022, 11:07 PMisEmpty
would be a method, but nope I can't find any reason. It doesn't do any expensive or long computation in the case of normal collections (just a size check) or Iterables/Sequences (just a hasNext
) check. Sure, hasNext theoretically could be "expensive", but I don't think that justifies it.
... wait, why isn't hasNext a property? 🤦ephemient
05/25/2022, 12:15 AMhasNext()
can be expensive, e.g.
generateSequence(2.toBigInteger()) { it.nextProbablePrime() }.iterator().hasNext()
but that doesn't apply to isEmpty()
since that's a method on Collection
and other types with a size