Expand description
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);
}
Traits§
- Tuple
Combinator - The traits that provides helper functions for tuples. This trait implementation mirros most of
the methods defined in
Option
. - Tuple
Reducer - Reduce tuples of
Option
s into results of various form, act in comparable to the iterators.