mapOr<U> method

  1. @override
  2. @useResult
U mapOr<U>(
  1. U map(
    1. T value
    ),
  2. U defaultValue
)
override

Returns the contained value, if any, with map applied to it, or defaultValue otherwise.

Examples

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

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

Implementation

@override
@useResult
U mapOr<U>(U Function(T value) map, U defaultValue) => map(value);