File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -670,6 +670,33 @@ macro_rules! map_impl {
670670 } ) . is_done( )
671671 }
672672
673+ /// Tests if at least one element of the iterator matches a predicate.
674+ ///
675+ /// Returns `true` if `predicate` evaluates to `true` for at least one element.
676+ /// Returns `false` if the input arrays are empty.
677+ ///
678+ /// Example:
679+ ///
680+ /// ```
681+ /// use ndarray::{array, Zip};
682+ /// let a = array![1, 2, 3];
683+ /// let b = array![1, 4, 9];
684+ /// assert!(Zip::from(&a).and(&b).any(|&a, &b| a == b));
685+ /// assert!(!Zip::from(&a).and(&b).any(|&a, &b| a - 1 == b));
686+ /// ```
687+ pub fn any<F >( mut self , mut predicate: F ) -> bool
688+ where F : FnMut ( $( $p:: Item ) ,* ) -> bool
689+ {
690+ self . for_each_core( ( ) , move |_, args| {
691+ let ( $( $p, ) * ) = args;
692+ if predicate( $( $p) ,* ) {
693+ FoldWhile :: Done ( ( ) )
694+ } else {
695+ FoldWhile :: Continue ( ( ) )
696+ }
697+ } ) . is_done( )
698+ }
699+
673700 expand_if!( @bool [ $notlast]
674701
675702 /// Include the producer `p` in the Zip.
You can’t perform that action at this time.
0 commit comments