transpose method
Transposes this Option<Result<T, E>> into a Result<Option<T>, E>.
Returns:
- Ok<Some<T>, E> if this
Option
is Some<Ok<T, E>>. - Err<T, E> if this
Option
is Some<Err<T, E>>. - Ok<None<T>, E> if this
Option
is None<Result<T, E>>.
Option<Result<int, String>> a = Some(Ok(1));
Result<Option<int>, String> b = Ok(Some(1));
print(a.transpose() == b); // prints: true
See also:
Rust: Option::transpose()
Implementation
Result<Option<T>, E> transpose() => switch (this) {
Some(value: Ok(value: T value)) => Ok(Some(value)),
Some(value: Err(value: E value)) => Err(value),
None() => Ok(None())
};