LetExtension<T> extension

Scope functions for null-safe operations

on
  • T?

Methods

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

Available on T?, provided by the LetExtension extension

Executes block if value is not null, returns the original value Usage: user?.also((it) => print(it.name))
ifNull(void block()) → void

Available on T?, provided by the LetExtension extension

Executes block if value is null Usage: user.ifNull(() => print('No user'))
let<R>(R block(T it)) → R?

Available on T?, provided by the LetExtension extension

Executes block if value is not null and returns the result Usage: user?.let((it) => it.name) ?? 'Guest'