Add `some` function to Iter

I suggest a new function to the iterators like JavaScript:

Function in JS:

let data = [
    { number: 1, letter: a },
    { number: 2, letter: b },
];

const hasNumber2 = data.some((e) => e.number == 2);
console.log(hasNumber2); // true

Expected in Rust:

struct Data {
    number: i64,
    letter: char,
}

fn main() {
    let data: Vec<Data> = vec![
        Data { number: 1, letter: 'a' },
        Data { number: 2, letter: 'b' }
    ];

    let hasNumber2 = data.iter().some(|d| d.number == 2);
    println!("{}", hasNumber2); // true
}

If accepted, I can work on it.

Is there some way this is distinct from Iterator::any?

8 Likes

Oh I didn't know it... Sorry for the post and thanks for the method :sweat_smile:

We could add a doc alias to help discover this -- e.g. Iterator::all has #[doc(alias = "every")].

20 Likes
7 Likes