4 releases
0.2.1 | Aug 28, 2019 |
---|---|
0.2.0 | Aug 21, 2019 |
0.1.1 | Aug 17, 2019 |
0.1.0 | Aug 16, 2019 |
#2844 in Rust patterns
1,427 downloads per month
25KB
267 lines
tuple-combinator
This crate provides a helper trait that implements several convenience method for tuples (up to 10-elements tuple). Implementing these methods directly for tuple Options can simplify your code a lot when working with many Options at once.
License
MIT
lib.rs
:
A helper trait to improve the ergonomics when working with multiple Option
s. After
importing TupleCombinator
, you can treat a tuple of Option
s as one Option
.
Example
use tuple_combinator::TupleCombinator;
fn main() {
let tuples = (Some(1), Some(2), Some(3));
assert_eq!(tuples.map(|(a,b,c)| a + b + c), Some(6));
assert_eq!(tuples.and_then(|(a,b,c)| Some(a + b - c)), Some(0));
assert_eq!(tuples.transpose(), Some((1,2,3)));
assert_eq!((Some(1), None).map(|(a, b): (i32, i32)| 100), None);
}