Is there a method like "Array.prototype.some" in rust Vector(or Iterator)?
[1,2,3,4,5].some(v => v > 3)
// ?
vec![1,2,3,4,5].some(|&v| v > 3)
Is there a method like "Array.prototype.some" in rust Vector(or Iterator)?
[1,2,3,4,5].some(v => v > 3)
// ?
vec![1,2,3,4,5].some(|&v| v > 3)
You're looking for Iterator::any.
vec![1,2,3,4,5].into_iter().any(|v| v > 3) // true
Incidentally, if you want the first matching element itself, not just a true or false, you can use Iterator::find.
vec![1,2,3,4,5].into_iter().find(|v| v > 3) // Some(4)