match<R> method

R match<R>(
  1. R someop(
    1. T
    ),
  2. R noneop()
)
inherited

Invokes either the someop or the noneop depending on the option.

This is an attempt at providing something similar to the Rust match expression, which makes it easy to handle both cases at once.

See also when for another way to achieve the same behavior.

Implementation

R match<R>(R Function(T) someop, R Function() noneop) {
  final val = toNullable();
  if (val != null) {
    return someop(val);
  } else {
    return noneop();
  }
}