LetExtension<T extends Object> extension

Kotlin-style scope functions for non-nullable types.

These extensions bring Kotlin's popular scope functions to Dart, enabling concise transformations and side effects without intermediate variables.

Example

final formatted = getUserName()
  .let((name) => name.toUpperCase())
  .also((name) => print('Processing: $name'));
on
  • T

Methods

also(void block(T it)) → T

Available on T, provided by the LetExtension extension

Executes block with this for side effects, then returns this.
let<R>(R block(T it)) → R

Available on T, provided by the LetExtension extension

Executes block with this as the argument and returns the result.
takeIf(bool predicate(T it)) → T?

Available on T, provided by the LetExtension extension

Returns this if it satisfies predicate, otherwise null.
takeUnless(bool predicate(T it)) → T?

Available on T, provided by the LetExtension extension

Returns this if it does NOT satisfy predicate, otherwise null.