Skip to content

Instantly share code, notes, and snippets.

@omkar-tenkale
Created October 5, 2022 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omkar-tenkale/68c4724c08bf767ff69013f990aab2a5 to your computer and use it in GitHub Desktop.
Save omkar-tenkale/68c4724c08bf767ff69013f990aab2a5 to your computer and use it in GitHub Desktop.
Vararg not null check
//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