okOrElse<E> method

  1. @override
  2. @useResult
Err<T, E> okOrElse<E>(
  1. E calculateError()
)
override

Transforms an Option into a Result, mapping Some to an Ok of the contained value and None to Err of the result of calculateError.

Examples

// prints "Ok(2)"
print(const Some(2).okOrElse(() => 'none'));

// prints "Err(none)"
print(const None<int>().okOrElse(() => 'none'));

Implementation

@override
@useResult
Err<T, E> okOrElse<E>(E Function() calculateError) => Err(calculateError());