okOr<E> abstract method

  1. @useResult
Result<T, E> okOr<E>(
  1. E error
)

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

Examples

// prints "Ok(2)"
print(const Some(2).okOr('none'));

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

Implementation

@useResult
Result<T, E> okOr<E>(E error);