Assign value to variable only if is not null – Kotlin
Another solution if You don’t want to return from function just yet: x?.let{ y = it } Which checks if x is non-null then passes it as the only parameter to the lambda block. This is also a safe call in case your x is a var.