whatIfNotNullAs

inline fun <R> Any?.whatIfNotNullAs(whatIf: (R) -> Unit): Any?

An expression for invoking whatIf when the target object is not null. If the target is not null and the target can be cast by the desired type R, the receiver will get a casted R type.

parcelable.whatIfNotNullAs<Poster> { poster ->
log(poster.name)
}

Return

Returns the desired type of object.

Parameters

whatIf

An executable lambda will receive a casted R if a target object is not null and the target can be cast by the desired type R.

inline fun <R> Any?.whatIfNotNullAs(whatIf: (R) -> Unit, whatIfNot: () -> Unit): Any?

An expression for invoking whatIf when the target object is not null. If the target is not null and the target can be cast by the desired type R, the receiver will get a casted R type. If the target is null, whatIfNot will be invoked instead of the whatIf without casting.

serializable.whatIfNotNullAs<Poster>(
whatIf = { poster -> log(poster.name) },
whatIfNot = {
// do something
})

Return

Returns the desired type of object.

Parameters

whatIf

@param whatIf An executable lambda will receive a casted R if a target object is not null and the target can be cast by the desired type R.

whatIfNot

An executable lambda if a target object is null or can not be cast by the desired type R.