NullableWhen<T> extension

Null-aware helpers for any nullable receiver T?: run a side effect, transform, or supply a fallback only when (or unless) the value is null.

Roadmap #351-365.

on
  • T?

Methods

mapNonNull<R>(R fn(T)) → R?

Available on T?, provided by the NullableWhen extension

Transforms a non-null value with fn, or returns null when the receiver is null.
orElse(T compute()) → T

Available on T?, provided by the NullableWhen extension

Returns the value when non-null, otherwise the result of compute.
whenNonNull(void fn(T)) → T?

Available on T?, provided by the NullableWhen extension

Runs fn with the value when it is non-null, then returns the original receiver unchanged (null or not) so calls can be chained.