LetExtensionNullable<T extends Object> extension
Kotlin-style scope functions for nullable types.
These extensions safely handle null values, executing blocks only when
the receiver is non-null.
Example
final result = maybeNull?.let((v) => v * 2) ?? 0;
- on
-
- T?
Methods
-
also(
void block(T it)) → T? -
Available on T?, provided by the LetExtensionNullable extension
Executesblockfor side effects when non-null, returning the original receiver. -
let<
R> (R block(T it)) → R? -
Available on T?, provided by the LetExtensionNullable extension
Executesblockwhen non-null, returning its result ornullif the receiver isnull. -
letNullable<
R> (R? block(T? it)) → R? -
Available on T?, provided by the LetExtensionNullable extension
Backwards-compatible variant that passes the nullable receiver toblock. -
letOr<
R> (R block(T it), {required R defaultValue}) → R -
Available on T?, provided by the LetExtensionNullable extension
Executesblockwhen non-null, returningdefaultValueif the receiver isnull. -
takeIf(
bool predicate(T it)) → T? -
Available on T?, provided by the LetExtensionNullable extension
Returns the receiver if non-null and satisfiespredicate, otherwisenull. -
takeUnless(
bool predicate(T it)) → T? -
Available on T?, provided by the LetExtensionNullable extension
Returns the receiver if non-null and does NOT satisfypredicate, otherwisenull.