Skip to main content

scan

Macro scan 

Source
macro_rules! scan {
    (zip!($($iae:expr),* $(,)?), $init:expr, |$acc:pat_param, ($($iip:pat_param),* $(,)?)| $body:expr) => { ... };
    (zip!($($iae:expr),* $(,)?), $init:expr, $fn:expr) => { ... };
    ($iae:expr, $init:expr, |$acc:pat_param, $iip:pat_param| $body:expr) => { ... };
    ($iae:expr, $init:expr, $fn:expr) => { ... };
}
Expand description

Produces an array of intermediate fold results in const contexts.

ยงExamples

use const_tools::scan;

const fn enumerate<T, const N: usize>(value: [T; N]) -> [(usize, T); N] {
    scan!(value, 0, |count, item| {
        let index = *count;
        *count += 1;
        (index, item)
    })
}