I believe it's always worked like that, but the difference is that without the preceding safe operator the context object will be of a nullable type inside the block, which generally isn't useful
j
Jonathan Olsson
11/11/2022, 3:25 PM
Especially when you use it to call some evil java library that spouts out NPEs... 🙈 Must have remembered this completely wrong then. Thanks!
k
Kevin Del Castillo
11/11/2022, 3:48 PM
Copy code
/**
* Calls the specified function [block] with `this` value as its argument and returns its result.
*
* For detailed usage information see the documentation for [scope functions](<https://kotlinlang.org/docs/reference/scope-functions.html#let>).
*/
@kotlin.internal.InlineOnly
public inline fun <T, R> T.let(block: (T) -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return block(this)
}