Is there any way to chain multiple lets for multiple nullable variables in kotlin?
fun example(first: String?, second: String?) {
first?.let {
se
I have upgraded the expected answer a bit:
inline fun ifLet(vararg elements: T?, closure: (List) -> R): R? {
return if (elements.all { it != null }) {
closure(elements.filterNotNull())
} else null
}
this makes this possible:
iflet("first", "sconed") {
// do somehing
} ?: run {
// do this if one of the params are null
}