hey so, contracts have been around for a while, bu...
# compiler
g
hey so, contracts have been around for a while, but the
single()
extension functions dont have htem. I thought that something like
Copy code
val myList: List<GeneralType> = ...
val x = myList.single { it is SpecificType }
would start to smartcast
x
to
SpecificType
instead of
GeneralType
during some upgrade given that we have contracts. But it hasnt. Is there a discussion about this somewhere? I was looking forward to it :(
e
I don't think contracts are able to express that, currently
Copy code
.firstNotNullOf { it as? SpecificType }
is close but a little different
g
i mean
firstIsInstance
is like a combination of
first
and
filterIsInstance
but i would have thought that a contract would let you say that the condition is true about the return value.... but i guess its an issue of changing the subject? I need to get in to contracts a bit more