let

inline fun <T, R> T.let(block: (T) -> R): R(source)

Calls block with this value and returns its result.

The value is passed as an argument (it in an unnamed lambda), even when it is null. Use a safe call, value?.let { ... }, to skip the block for a null receiver. The block runs once; its exceptions propagate and it supports non-local returns.

val size = "hello".let { it.length }

Receiver

value passed to the block.

Return

the value produced by block.

Parameters

block

transformation to run once.

Type Parameters

T

type of the receiver, which may be nullable.

R

type of the block result.

See also