https://kotlinlang.org logo
Title
h

Hamza

11/02/2018, 4:59 AM
hi, is there more documentation on contracts? i’ve seen a bit of stuff, but not sometthing like what i am looking for. is that trying to confirm all of the varargs provided aren’t null:
@UseExperimental(ExperimentalContracts::class)
fun anyNotNull(vararg arguments: Any?, block: () -> Unit): Boolean {
    contract {
        returns(true) implies /* Something here that tells the compiler that all arguments are not null */
    }
    if(arguments.any { it == null }) {
        block()
        return false
    }
    return true
}
g

gildor

11/02/2018, 5:06 AM
not sure that it’s supported. Probably KEEP is the best source of information about contrcats
h

Hamza

11/02/2018, 5:06 AM
kk
could i do something like this?
inline fun anyNotNull(vararg arguments: String?, block: () -> Unit) {
    if(arguments.any { !isNotNull(it) }) {
        block()
    }
}

@UseExperimental(ExperimentalContracts::class)
fun isNotNull(arg: String?): Boolean {
    contract { 
        returns(true) implies (arg != null)
    }
    return arg != null
}
aww, it didn’t work
g

gildor

11/02/2018, 5:18 AM
h

Hamza

11/02/2018, 5:18 AM
kk