5 releases (breaking)

Uses old Rust 2015

0.4.0 May 11, 2018
0.3.0 Apr 17, 2018
0.2.0 Apr 7, 2018
0.1.0 Mar 18, 2018
0.0.1 Mar 11, 2018

#2726 in Rust patterns

Download history 467/week @ 2024-03-25 285/week @ 2024-04-01 213/week @ 2024-04-08 170/week @ 2024-04-15 194/week @ 2024-04-22 143/week @ 2024-04-29 113/week @ 2024-05-06 220/week @ 2024-05-13 314/week @ 2024-05-20 461/week @ 2024-05-27 420/week @ 2024-06-03 229/week @ 2024-06-10 241/week @ 2024-06-17 137/week @ 2024-06-24 203/week @ 2024-07-01 95/week @ 2024-07-08

687 downloads per month
Used in 3 crates

MIT license

27KB
548 lines

tuple-map

Build Status Documentation License: MIT

This library provides iterator-like utility methods like map, fold, for_each, and etc., for tuples whose all elements are same type(i.e. (T, T), (T, T, T), (T, T, T, T)...)

Example

extern crate tuple_map;
use tuple_map::*;
fn main() {
    let (x, y) = (3, 4);
    let (x, y) = (x, y).map(|a| a + 5);
    assert_eq!(x, 8);
    assert_eq!(y, 9);

    let v = (3, 4, 5, 6).fold(vec![], |mut v, x| {
        if x % 3 == 0 {
            v.push(x);
        }
        v
    });
    assert_eq!(v, vec![3, 6]);

    assert!((3, 3, 3).same());

    assert_eq!((3, 4, 5).nth(1), Some(4));

    assert_eq!((3, 4, 5).add(1, 2, 3), (4, 6, 8));

    let a = (1, 2, 3);
    let b = ("a", "b", "c");
    assert_eq!(
        a.zipf(b, |x, y| format!("{}{}", x, y)),
        ("1a", "2b", "3c").map(|x| x.to_owned())
    );

    assert_eq!(a.sum(), 6);

    assert_eq!(a.tmax(), 3);
    assert_eq!(a.tmin(), 1);
}

No runtime deps