Not sure where to ask this π
Regarding Contracts, I was wondering if itβs possible (or will ever be) to signal something about a parameter if a lambda is called.
Like this:
pablisco
03/08/2022, 11:49 PM
This would mean that, if the block is run, then the subject is not null (or other condition)
l
louiscad
03/09/2022, 12:01 AM
I think
stuff?.let { }
does the same thing as what you want, do you have another use case?
β 1
p
pablisco
03/10/2022, 12:33 PM
Yeah that one does, however this case is a replacement for:
calls(block) implies (subject is AppCompatActivity)
Then we could define something like:
Copy code
fun Activity.ifAppCompat(block: () -> R): R {
contract {
calls(block) implies (this is AppCompatActivity)
}
if(this is AppCompatActivity) {
block()
}
}
That said, these could potentially be inferred by the compiler. But making it explicit will probably be more efficient
(say someone that knows close to nothing about the Kotlin compiler π )
l
louiscad
03/10/2022, 2:16 PM
That AppCompat example is less abstract, but can't you simply add an