Czar
02/23/2018, 12:04 PMinline fun ifNoneAreNull(vararg args: Any?, operation: (args: Array<out Any>) -> Unit) {
@Suppress("UNCHECKED_CAST")
if (null !in args) operation(args as Array<out Any>)
}
//usage
ifNoneAreNull("a", "b", 3, null) { args ->
args.forEach (::println)
}
But if your use case is exactly like you described above, your solution looks ok and is better (if arguably less flexible) than mine.