#tuple #options #combinator #traits #helper #dealing

tuple-combinator

Convenience methods for dealing with Option tuples

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

#2898 in Rust patterns

Download history 6/week @ 2023-11-27 50/week @ 2023-12-04 55/week @ 2024-01-22 49/week @ 2024-01-29 1/week @ 2024-02-05 45/week @ 2024-02-12 155/week @ 2024-02-19 77/week @ 2024-02-26 111/week @ 2024-03-04 21/week @ 2024-03-11

364 downloads per month

MIT license

25KB
267 lines

tuple-combinator

Build Status Crates.io docs.rs

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 Options. After importing TupleCombinator, you can treat a tuple of Options 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);
}

No runtime deps