ifNotNull

fun <T> T?.ifNotNull(action: (T) -> Unit): T?

Executes a given block of code if the value of this nullable type is not null. This function allows for safe, chained operations on a nullable object, similar to let, but it returns the original receiver (this) instead of the result of the lambda. This is useful for performing side effects on a non-null value without altering the flow.

Return

The original nullable object, allowing for further chaining.

Parameters

action

The block of code to execute, which receives the non-null value as its argument.

Type Parameters

T

The type of the value.