mapOrElse<U> method

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

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

Examples

// prints "4"
print(const Ok<int, String>(2).mapOrElse((value) => value * 2, (_) => 0));

// prints "0"
print(const Err<int, String>('error').mapOrElse((value) => value * 2, (_) => 0));

Implementation

@override
@useResult
U mapOrElse<U>(U Function(T value) map, U Function(E error) calculateDefaultValue) => map(value);