Hi,
I’m not sure what to title this post. I don’t think the type system can help me here, and I probably just need to use !!
, but I wanted to check.
Say I have a type like this:
class Thing {
var txnID: String
var expiresDate: Instant?
...
}
I have a list of them and I filter
in a way that only gets elements with non-null expiresDate
:
val things: List<Thing> = ...
val nonExpired = things.filter { it.expiresDate != null && now.isBefore(it.expiresDate) }
for (thing in nonExpired) {
useTheDate(thing.expiresDate!!)
}
In a way, I’ve proved that I don’t need the !!
, but I guess if I want to use the type system to encode that, I’d need another type (named ??) that would look like Thing
expect have a non-nullable expiresDate
.
There’s not some other slick way, is there?
Rob