LetExtensionNullable<T extends Object> extension

Kotlin-style let helpers for nullable types.

on
  • T?

Methods

also(void block(T it)) → T?

Available on T?, provided by the LetExtensionNullable extension

Executes block when non-null and returns the original receiver.
let<R>(R block(T it)) → R?

Available on T?, provided by the LetExtensionNullable extension

Executes block when the receiver is non-null, returning its result.
letNullable<R>(R? block(T? it)) → R?

Available on T?, provided by the LetExtensionNullable extension

Back-compat variant whose block accepts a nullable receiver.
letOr<R>(R block(T it), {required R defaultValue}) → R

Available on T?, provided by the LetExtensionNullable extension

Executes block when non-null, otherwise returns defaultValue.
takeIf(bool predicate(T it)) → T?

Available on T?, provided by the LetExtensionNullable extension

Returns the receiver if non-null and it satisfies predicate, else null.
takeUnless(bool predicate(T it)) → T?

Available on T?, provided by the LetExtensionNullable extension

Returns the receiver if non-null and it does NOT satisfy predicate, else null.