when method

T? when(
  1. bool predicate(
    1. T self
    ), {
  2. T? orElse(
    1. T self
    )?,
})

Returns the result of orElse if predicate returns false, otherwise returns this.

Implementation

T? when(bool Function(T self) predicate, {T? Function(T self)? orElse}) =>
    predicate(this) ? this : orElse?.call(this);