mapOrElse<U> method
- @override
- @useResult
- U map(
- T value
- U calculateDefaultValue(
- 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);