https://github.com/upsuper/tuple-transpose
Transpose tuple of results and options to result and option of tuple
https://github.com/upsuper/tuple-transpose
Last synced: 4 months ago
JSON representation
Transpose tuple of results and options to result and option of tuple
- Host: GitHub
- URL: https://github.com/upsuper/tuple-transpose
- Owner: upsuper
- License: mit
- Created: 2019-11-02T00:12:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-02T01:02:12.000Z (over 5 years ago)
- Last Synced: 2025-02-28T11:54:12.811Z (4 months ago)
- Language: Rust
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tuple-transpose
[](https://dev.azure.com/upsuper/upsuper/_build/latest?definitionId=3&branchName=master)
[](https://crates.io/crates/tuple-transpose)Transpose a tuple of results or options to result or option of tuple.
## Examples
```rust
// Result
assert_eq!((Ok::<_, ()>(1u32), Ok(2.0f32)).transpose(), Ok((1u32, 2.0f32)));
assert_eq!((Ok(1u32), Err::(2.0f32)).transpose(), Err(2.0f32));
assert_eq!((Err::(1u32), Ok(2.0f32)).transpose(), Err(1u32));// Option
assert_eq!((Some(1u32), Some(2.0f32)).transpose(), Some((1u32, 2.0f32)));
assert_eq!((Some(1u32), None::).transpose(), None::<(u32, f32)>);
assert_eq!((None::, Some(2.0f32)).transpose(), None::<(u32, f32)>);
```