Created
February 19, 2025 11:58
-
-
Save mutkuensert/e1467404e17388344ab50eb0cb26f71c to your computer and use it in GitHub Desktop.
Useful null check methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.contracts.ExperimentalContracts | |
import kotlin.contracts.contract | |
@OptIn(ExperimentalContracts::class) | |
fun allNotNull( | |
arg1: Any?, | |
arg2: Any?, | |
arg3: Any? = Any(), | |
arg4: Any? = Any(), | |
arg5: Any? = Any() | |
): Boolean { | |
contract { | |
returns(true) implies (arg1 != null && arg2 != null && arg3 != null && arg4 != null && arg5 != null) | |
} | |
return arg1 != null && arg2 != null && arg3 != null && arg4 != null && arg5 != null | |
} | |
@OptIn(ExperimentalContracts::class) | |
fun isAnyNull( | |
arg1: Any?, | |
arg2: Any?, | |
arg3: Any? = Any(), | |
arg4: Any? = Any(), | |
arg5: Any? = Any() | |
): Boolean { | |
contract { | |
returns(false) implies (arg1 != null && arg2 != null && arg3 != null && arg4 != null && arg5 != null) | |
} | |
return !(arg1 != null && arg2 != null && arg3 != null && arg4 != null && arg5 != null) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment