Iterator: all the elements



examples/iterators/all/src/main.rs
fn main() {
    let numbers = vec![23, 7, 12, 8];

    if numbers.iter().all(|num| *num > 0) {
        println!("Positive numbers");
    }
    if numbers.iter().all(|num| *num >= 10) {
        println!("Double digit numbers");
    }

    if numbers.into_iter().all(|num| num > 0) {
        println!("Positive numbers");
    }

    // use of moved value: `numbers`
    // if numbers.into_iter().all(|num| num >= 10) {
    //     println!("Double digit numbers");
    // }

    let numbers = vec![23, 12, 7, 8];

    if numbers.iter().all(big) {
        println!("Double digit numbers");
    }

    if numbers.into_iter().all(|num| {
        println!("Checking {num}");
        num >= 10
    }) {
        println!("Double digit numbers");
    }
}

fn big(num: &i32) -> bool {
    println!("Checking in big {num}");
    *num >= 10
}

Positive numbers
Positive numbers
Checking 23
Checking 12
Checking 7