onNotNull

inline fun Any?.onNotNull(block: () -> Unit)

Executes the given block only if the receiver object is not null.

This function provides a concise and readable way to perform an action on a nullable object, avoiding an explicit null check.

Example:

val name: String? = "John"
name.onNotNull {
println("Name is not null")
}

Parameters

block

The block of code to execute if the object is not null.