dsalgo/
flat_nonzero_with_to_bool.rs

1//! inspired by numpy.flatnonzero
2
3use crate::convert_to_bool::ToBool;
4
5pub fn flat_nonzero<T: ToBool>(a: &[T]) -> Vec<usize> {
6    a.iter()
7        .enumerate()
8        .filter_map(|(i, x)| if x.to_bool() { Some(i) } else { None })
9        .collect()
10}
11
12#[cfg(test)]
13
14mod tests {
15
16    #[test]
17
18    fn test() {}
19}