I've heard that let is used when you wish to perform a null safe operation on an Object by using the safe call operator ?.
.(according to this)
But the question is why this:
fun main() {
var s: String? = null
s = s?.let{ it.toUpperCase() }
println(s)
}
is preferred over this:
fun main() {
var s: String? = null
s = s?.toUpperCase()
println(s)
}
In my opinion the 2nd variant is easier to read and understand which makes let useless.
So what is the purpose of let function?