[][src]Trait higher_order_functions::Zip

pub trait Zip {
    type TLhs;
    type TSelf;
    fn zip<TRhs, TTo, F: FnMut(Self::TLhs, TRhs) -> TTo>(
        self,
        rhs: Self::TSelf,
        f: F
    ) -> Self::TSelf; }

Zip two collections using a function to combine pairs of elements.

Examples

Zipping two arrays of different types into a single array of tuples:

use higher_order_functions::Zip;

let a = [1, 2, 3];
let b = ["a", "b", "c"];

let arr = a.zip(b, |ax, bx| (ax, bx));

assert_eq!(arr, [(1, "a"), (2, "b"), (3, "c")]);

Zipping two arrays by multiplying each pair of elements:

use higher_order_functions::Zip;

let a = [1, 2, 3];
let b = [4, 5, 6];

let arr = a.zip(b, |ax, bx| ax * bx);

assert_eq!(arr, [4, 10, 18]);

Associated Types

type TLhs

The type parameter of Self.

Self: TSelf<TLhs>

type TSelf

The generic type of Self.

Self: TSelf<TLhs>

Loading content...

Required methods

fn zip<TRhs, TTo, F: FnMut(Self::TLhs, TRhs) -> TTo>(
    self,
    rhs: Self::TSelf,
    f: F
) -> Self::TSelf

Apply f to each pair of elements in self and rhs and return the results.

Loading content...

Implementations on Foreign Types

impl<TLhs, const N: usize> Zip for [TLhs; N][src]

Zip two arrays using a function to combine pairs of elements.

type TLhs = TLhs

type TSelf = [T; N]

Loading content...

Implementors

Loading content...