Scope Functions: let, apply, also, run, with
Five small functions that make object configuration and null handling read naturally.
Scope functions run a block of code in the context of an object. They differ in two ways: whether the object is available as this or it, and whether they return the object itself or the block's result.
All five
obj?.let { it.a }?.let { it.b }?.let { it.c }?.also { ... } // long chains
Use plain local variables when a chain gets hard to read Scope functions improve short, focused code; deeply nested chains make it harder to follow.
Which scope function returns the object and refers to it as this?