Trait tuple_map::TupleMap2
[−]
[src]
pub trait TupleMap2 {
type Item;
fn all<F>(self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool;
fn any<F>(self, f: F) -> bool
where
F: FnMut(Self::Item) -> bool;
fn by_ref(&self) -> (&Self::Item, &Self::Item);
fn by_ref_mut(&mut self) -> (&mut Self::Item, &mut Self::Item);
fn find<F>(self, f: F) -> Option<Self::Item>
where
F: FnMut(&Self::Item) -> bool;
fn fold<B, F>(self, init: B, f: F) -> B
where
F: FnMut(B, Self::Item) -> B;
fn for_each<F>(self, f: F)
where
F: FnMut(Self::Item);
fn id(self) -> (Self::Item, Self::Item);
fn into_vec(self) -> Vec<Self::Item>;
fn map<B, F>(self, f: F) -> (B, B)
where
F: FnMut(Self::Item) -> B;
fn nth(self, i: usize) -> Option<Self::Item>;
fn same(self) -> bool
where
Self::Item: PartialEq;
fn same_as(self, i: Self::Item) -> bool
where
Self::Item: PartialEq;
fn sum(self) -> Self::Item
where
Self::Item: AddAssign;
fn product(self) -> Self::Item
where
Self::Item: MulAssign;
fn zip<U, B>(self, other: U) -> ((Self::Item, B), (Self::Item, B))
where
U: TupleMap2<Item = B>;
fn zipf<U, I, F, B>(self, other: U, f: F) -> (B, B)
where
U: TupleMap2<Item = I>,
F: FnMut(Self::Item, I) -> B;
fn cloned(&self) -> (Self::Item, Self::Item)
where
Self::Item: Clone,
{ ... }
fn add<U, I, B>(self, other: U) -> (B, B)
where
U: TupleMap2<Item = I>,
Self::Item: Add<I, Output = B>,
Self: Sized,
{ ... }
fn sub<U, I, B>(self, other: U) -> (B, B)
where
U: TupleMap2<Item = I>,
Self::Item: Sub<I, Output = B>,
Self: Sized,
{ ... }
fn mul<U, I, B>(self, other: U) -> (B, B)
where
U: TupleMap2<Item = I>,
Self::Item: Mul<I, Output = B>,
Self: Sized,
{ ... }
fn div<U, I, B>(self, other: U) -> (B, B)
where
U: TupleMap2<Item = I>,
Self::Item: Div<I, Output = B>,
Self: Sized,
{ ... }
}
Associated Types
type Item
Required Methods
fn all<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
F: FnMut(Self::Item) -> bool,
Checks if every element of tuple matches a predicate, like
std::iter::Iterator::all.
This method take a closure returns true or false, and tries to apply this
closure to all elements of tuple. If and only if all of them returns true,
this method return true.
Examples
let a = (3, 9, 12, ...); assert!(a.all(|x| x % 3 == 0)); assert!(!a.all(|x| x % 4 == 0));
fn any<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool,
F: FnMut(Self::Item) -> bool,
Checks if any element of tuple matches a predicate, like
std::iter::Iterator::any.
This method take a closure returns true or false, and tries to apply this
closure to all elements of tuple. If any of them returns true,
this method return true.
Examples
let a = (3, 9, 12, ...); assert!(a.any(|x| x % 4 == 0)); assert!(!a.any(|x| x % 7 == 0));
fn by_ref(&self) -> (&Self::Item, &Self::Item)
Takes &(a, a, a, ...) and returns (&a, &a, &a, ...)
Examples
let a = (3, 3, 3, ...); assert_eq!(a.by_ref(), (&3, &3, &3, ...));
fn by_ref_mut(&mut self) -> (&mut Self::Item, &mut Self::Item)
Takes &mut (a, a, a, ...) and returns (&mut a, &mut a, &mut a, ...)
Examples
let a = (3, 3, 3, ...); assert_eq!(a.by_ref(), (&mut 3, &mut 3, &mut 3, ...));
fn find<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(&Self::Item) -> bool,
F: FnMut(&Self::Item) -> bool,
Find the leftest element which satisfies f and returns it.
Example
let mut a = (3, 3, 5, 3, ...); if let Some(x) = a.by_ref_mut().find(|&&mut x| x == 5) { *x = 3 } assert!(a.same());
fn fold<B, F>(self, init: B, f: F) -> B where
F: FnMut(B, Self::Item) -> B,
F: FnMut(B, Self::Item) -> B,
Takes a closure f and applies it to all elements to tuple, and produce single value.
This is similar to std::iter::Iterator::fold
Example
let a = (3, 4, 5, ...) let sum = a.fold(0, |sum, x| sum + x);
fn for_each<F>(self, f: F) where
F: FnMut(Self::Item),
F: FnMut(Self::Item),
Takes a closure f and applies it to all elements to tuple.
f can cause side effect(because it's FnMut), but this method return nothing.
Similar to std::iter::Iterator::for_each
Example
let a = (3, 4, 5, ...); let mut sum = 0; a.for_each(|x| sum += x);
fn id(self) -> (Self::Item, Self::Item)
return Self. It's not intended to used by user.
fn into_vec(self) -> Vec<Self::Item>
Convert tuple into Vec.
Example
let a = (3, 4, 5, ...) assert_eq(a.into_vec(), vec![3, 4, 5, ...])
fn map<B, F>(self, f: F) -> (B, B) where
F: FnMut(Self::Item) -> B,
F: FnMut(Self::Item) -> B,
Takes a closure f and (a, a, a, ...), then returns (f(a), f(a), f(a), ...).
Similar to std::iter::Iterator::map.
Example
let a = (3, 4, 5, ...); assert_eq!(a.map(|x| x * 2), (6, 8, 10, ...));
fn nth(self, i: usize) -> Option<Self::Item>
return nth element in the tuple.
Example
let a = (3, 4, 5, ..); assert_eq!(a.nth(2), Some(5));
fn same(self) -> bool where
Self::Item: PartialEq,
Self::Item: PartialEq,
Checks if all elements of the tuple is same.
Example
let a = (3, 3, 3, ...); assert!(a.same());
fn same_as(self, i: Self::Item) -> bool where
Self::Item: PartialEq,
Self::Item: PartialEq,
Takes i and checks if all elements of the tuple is same as i.
Example
let a = (3, 3, 3, ...); assert!(a.same_as(3));
fn sum(self) -> Self::Item where
Self::Item: AddAssign,
Self::Item: AddAssign,
Takes (a, b, c, ...) then returns a + b + c ...
fn product(self) -> Self::Item where
Self::Item: MulAssign,
Self::Item: MulAssign,
Takes (a, b, c, ...) then returns a + b + c ...
fn zip<U, B>(self, other: U) -> ((Self::Item, B), (Self::Item, B)) where
U: TupleMap2<Item = B>,
U: TupleMap2<Item = B>,
Takes (a, a, a, ...) and (b, b, b, ...) then returns ((a, b), (a, b), (a, b), ...)
Example
let a = (3, 4, 5, ...); let b = ('a', 'b', 'c', ...); assert_eq!(a.zip(b), ((3, 'a'), (4, 'b'), (5, 'c'), ...));
fn zipf<U, I, F, B>(self, other: U, f: F) -> (B, B) where
U: TupleMap2<Item = I>,
F: FnMut(Self::Item, I) -> B,
U: TupleMap2<Item = I>,
F: FnMut(Self::Item, I) -> B,
Takes (a, a, a, ...) and (b, b, b, ...) and closure f,
then returns (f(a, b), f(a, b), f(a, b), ...)
Example
let a = (3, 4, 5, ...); let b = ('a', 'b', 'c', ...); assert_eq!( a.zipf(b, |x, y| format!("{}{}", x, y)), ("3a", "4b", "5c", ...).map(|x| x.to_owned()) );
Provided Methods
fn cloned(&self) -> (Self::Item, Self::Item) where
Self::Item: Clone,
Self::Item: Clone,
Takes &(a, a, a, ...) and returns (a, a, a, ...)
Examples
let a = (3, 3, 3, ..,); assert_eq!(a, a.clone());
fn add<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Add<I, Output = B>,
Self: Sized,
U: TupleMap2<Item = I>,
Self::Item: Add<I, Output = B>,
Self: Sized,
Takes (a, a, a, ...) and (b, b, b, ...),
then returns (a + b, a + b, a + b, ...)
Example
let a = (3, 4, 5, ...); let b = (7, 8, 9, ....) assert_eq!(a.add(b), (10, 12, 14, ...));
fn sub<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Sub<I, Output = B>,
Self: Sized,
U: TupleMap2<Item = I>,
Self::Item: Sub<I, Output = B>,
Self: Sized,
Takes (a, a, a, ...) and (b, b, b, ...),
then returns (a - b, a - b, a - b, ...)
Example
let a = (7, 8, 9, ....); let b = (3, 4, 5, ....); assert!(a.sub(b).same());
fn mul<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Mul<I, Output = B>,
Self: Sized,
U: TupleMap2<Item = I>,
Self::Item: Mul<I, Output = B>,
Self: Sized,
Takes (a, a, a, ...) and (b, b, b, ...),
then returns (a * b, a * b, a * b, ...)
Example
let a = (7, 8, 9, ....); let b = (3, 4, 5, ....); assert_eq!(a.mul(b), (21, 32, 45, ...));
fn div<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Div<I, Output = B>,
Self: Sized,
U: TupleMap2<Item = I>,
Self::Item: Div<I, Output = B>,
Self: Sized,
Takes (a, a, a, ...) and (b, b, b, ...),
then returns (a * b, a * b, a * b, ...)
Example
let a = (6, 8, 10, ....); let b = (3, 4, 5, ....); assert!(a.div(b).same());
Implementations on Foreign Types
impl<T> TupleMap2 for (T, T)[src]
type Item = T
fn any<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool, [src]
F: FnMut(Self::Item) -> bool,
fn all<F>(self, f: F) -> bool where
F: FnMut(Self::Item) -> bool, [src]
F: FnMut(Self::Item) -> bool,
fn by_ref(&self) -> (&Self::Item, &Self::Item)[src]
fn by_ref_mut(&mut self) -> (&mut Self::Item, &mut Self::Item)[src]
fn find<F>(self, f: F) -> Option<Self::Item> where
F: FnMut(&Self::Item) -> bool, [src]
F: FnMut(&Self::Item) -> bool,
fn fold<B, F>(self, init: B, f: F) -> B where
F: FnMut(B, Self::Item) -> B, [src]
F: FnMut(B, Self::Item) -> B,
fn for_each<F>(self, f: F) where
F: FnMut(Self::Item), [src]
F: FnMut(Self::Item),
fn id(self) -> (Self::Item, Self::Item)[src]
fn into_vec(self) -> Vec<Self::Item>[src]
fn nth(self, i: usize) -> Option<Self::Item>[src]
fn map<B, F>(self, f: F) -> (B, B) where
F: FnMut(Self::Item) -> B, [src]
F: FnMut(Self::Item) -> B,
fn same(self) -> bool where
Self::Item: PartialEq, [src]
Self::Item: PartialEq,
fn same_as(self, i: Self::Item) -> bool where
Self::Item: PartialEq, [src]
Self::Item: PartialEq,
fn sum(self) -> Self::Item where
Self::Item: AddAssign, [src]
Self::Item: AddAssign,
fn product(self) -> Self::Item where
Self::Item: MulAssign, [src]
Self::Item: MulAssign,
fn zip<U, B>(self, other: U) -> ((Self::Item, B), (Self::Item, B)) where
U: TupleMap2<Item = B>, [src]
U: TupleMap2<Item = B>,
fn zipf<U, I, F, B>(self, other: U, f: F) -> (B, B) where
U: TupleMap2<Item = I>,
F: FnMut(Self::Item, I) -> B, [src]
U: TupleMap2<Item = I>,
F: FnMut(Self::Item, I) -> B,
fn cloned(&self) -> (Self::Item, Self::Item) where
Self::Item: Clone, [src]
Self::Item: Clone,
fn add<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Add<I, Output = B>,
Self: Sized, [src]
U: TupleMap2<Item = I>,
Self::Item: Add<I, Output = B>,
Self: Sized,
fn sub<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Sub<I, Output = B>,
Self: Sized, [src]
U: TupleMap2<Item = I>,
Self::Item: Sub<I, Output = B>,
Self: Sized,
fn mul<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Mul<I, Output = B>,
Self: Sized, [src]
U: TupleMap2<Item = I>,
Self::Item: Mul<I, Output = B>,
Self: Sized,
fn div<U, I, B>(self, other: U) -> (B, B) where
U: TupleMap2<Item = I>,
Self::Item: Div<I, Output = B>,
Self: Sized, [src]
U: TupleMap2<Item = I>,
Self::Item: Div<I, Output = B>,
Self: Sized,