Created
October 5, 2022 08:15
-
-
Save omkar-tenkale/68c4724c08bf767ff69013f990aab2a5 to your computer and use it in GitHub Desktop.
Vararg not null check
This file contains 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
//approach 1 | |
fun main(){ | |
val a = Unit | |
val b = null | |
if(listOf(a,b).all{ it != null }){ | |
println("Not null") | |
}else{ | |
print("Please check inputs") | |
} | |
} | |
//approach 2 | |
fun <T> ifNotNull(vararg values : T?,block :() -> Unit){ | |
if(values.all{ it != null }){ | |
block() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment