#find #iterator #index #predicate #elements #identical #first

find_all

A (nearly) identical alternative for Iterator::find which returns an Option<Vec<usize>> containing all elements which meet a given predicate (instead of just the first)

4 stable releases

2.0.0 Jun 29, 2022
1.0.2 Jun 27, 2022

#1856 in Rust patterns

Download history 20/week @ 2024-04-07 33/week @ 2024-04-14 27/week @ 2024-04-21 23/week @ 2024-04-28 36/week @ 2024-05-05 14/week @ 2024-05-12 32/week @ 2024-05-19 26/week @ 2024-05-26 28/week @ 2024-06-02 10/week @ 2024-06-09 8/week @ 2024-06-16 13/week @ 2024-06-23 2/week @ 2024-06-30 32/week @ 2024-07-07 61/week @ 2024-07-14 70/week @ 2024-07-21

167 downloads per month

GPL-3.0-only

5KB

find_all

find_all is capable of finding all indexes of elements where a given predicate is met and therefore aims to be a simple alternative with (nearly) identical interface to the find method (this difference being returning an Option<Vec<usize>> instead of Option<usize>)

use find_all::FindAll;
let test_data = [1, 2, 3, 4, 1, 1, 1, 1];
let indexes = test_data.iter().find_all(|num: &&i32| **num == 9);
assert_eq!(indexes, None);

let indexes = test_data.iter().find_all(|num: &&i32| **num == 1);
assert_eq!(indexes, Some(vec![0,4,5,6,7]));

License: GPL-3.0-only


lib.rs:

find_all is capable of finding all indexes of elements where a given predicate is met and therefore aims to be a simple alternative with (nearly) identical interface to the find method (this difference being returning an Option<Vec<usize>> instead of Option<usize>)

use find_all::FindAll;
let test_data = [1, 2, 3, 4, 1, 1, 1, 1];
let indexes = test_data.iter().find_all(|num: &&i32| **num == 9);
assert_eq!(indexes, None);

let indexes = test_data.iter().find_all(|num: &&i32| **num == 1);
assert_eq!(indexes, Some(vec![0,4,5,6,7]));

No runtime deps