mapOrElse<U> abstract method

  1. @useResult
U mapOrElse<U>(
  1. U map(
    1. T value
    ),
  2. U calculateDefaultValue()
)

Returns the contained value, if any, with map applied to it, or the result of calculateDefaultValue otherwise.

Examples

// prints "some: 2"
print(const Some(2).mapOrElse((value) => 'some: $value', () => 'none'));

// prints "none"
print(const None<int>().mapOrElse((value) => 'some: $value', () => 'none'));

Implementation

@useResult
U mapOrElse<U>(U Function(T value) map, U Function() calculateDefaultValue);