whatIfNotNullWith

inline fun <T, R> T?.whatIfNotNullWith(whatIf: (T) -> R, whatIfNot: (T?) -> R): R

An expression for invoking whatIf when the T target object is not null. If the T target is null, whatIfNot will be invoked instead of the whatIf. It is useful when the receiver T and the result R should be different.

Return

Returns the desired type of object.

Parameters

whatIf

An executable lambda if a target object is not null and returns a different type R.

whatIfNot

An executable lambda if a target object is null and returns a different type R.