Function rufl::collection::some_match

source ·
pub fn some_match<C: AsRef<[T]>, T>(
    collection: &C,
    predicate: impl Fn(&T, usize) -> bool
) -> bool
Expand description

Returns true if any element of the collection pass the predicate function check.

  • predicate function signature: fn(item: &T, index: usize) -> bool

§Arguments

  • collection - The collection to iterate over.

  • predicate - The function invoked per iteration.

§Returns

Returns true if any element pass the predicate check, else false.

§Examples

use rufl::collection;

assert_eq!(true, collection::some_match(&[1, 4, 5], &|n: &i32, _i: usize| *n <= 3));

assert_eq!(false, collection::some_match(&vec![1, 2, 3], &|n: &i32, _i: usize| *n > 3));