Crates.io | tuple-map |
lib.rs | tuple-map |
version | 0.4.0 |
source | src |
created_at | 2018-03-11 14:13:34.520283 |
updated_at | 2018-05-11 05:28:37.867518 |
description | map methods for tuple |
homepage | https://github.com/kngwyu/tuple-map |
repository | https://github.com/kngwyu/tuple-map |
max_upload_size | |
id | 54994 |
size | 27,519 |
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)...
)
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);
}