Skip to main content

zip_with

Macro zip_with 

Source
macro_rules! zip_with {
    ($($f:ident,)? ($e:expr $(, $rest:expr)*), $($move:ident)? |$($i:ident),+ $(,)?| $($work:tt)*) => { ... };
    ($($f:ident,)? ($e:expr $(, $rest:expr)*), $worker:ident, $($move:ident,)? |$($i:ident),+ $(,)?|  $($work:tt)*) => { ... };
}
Expand description

Macros to give syntactic sugar for zipWith pattern and variants.

use crate::spartan::zip_with;
use itertools::Itertools as _; // we use zip_eq to zip!
let v = vec![0, 1, 2];
let w = vec![2, 3, 4];
let y = vec![4, 5, 6];

// Using the `zip_with!` macro to zip three iterators together and apply a closure
// that sums the elements of each iterator.
let res = zip_with!((v.iter(), w.iter(), y.iter()), |a, b, c| a + b + c)
    .collect::<Vec<_>>();

println!("{:?}", res); // Output: [6, 9, 12]