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