@@ -117,6 +117,9 @@ module Data.Array
117117 , zip
118118 , unzip
119119
120+ , any
121+ , all
122+
120123 , foldM
121124 , foldRecM
122125
@@ -136,7 +139,7 @@ import Data.Array.NonEmpty.Internal (NonEmptyArray(..))
136139import Data.Array.ST as STA
137140import Data.Array.ST.Iterator as STAI
138141import Data.Foldable (class Foldable, foldl, foldr, traverse_)
139- import Data.Foldable (foldl, foldr, foldMap, fold, intercalate, any, all ) as Exports
142+ import Data.Foldable (foldl, foldr, foldMap, fold, intercalate) as Exports
140143import Data.Maybe (Maybe(..), maybe, isJust, fromJust, isNothing)
141144import Data.Traversable (sequence, traverse)
142145import Data.Tuple (Tuple(..), fst, snd)
@@ -1051,7 +1054,7 @@ nubByEq :: forall a. (a -> a -> Boolean) -> Array a -> Array a
10511054nubByEq eq xs = ST.run do
10521055 arr <- STA.empty
10531056 ST.foreach xs \x -> do
1054- e <- not <<< Exports. any (_ `eq` x) <$> (STA.unsafeFreeze arr)
1057+ e <- not <<< any (_ `eq` x) <$> (STA.unsafeFreeze arr)
10551058 when e $ void $ STA.push x arr
10561059 STA.unsafeFreeze arr
10571060
@@ -1208,6 +1211,28 @@ unzip xs =
12081211 snds' <- STA.unsafeFreeze snds
12091212 pure $ Tuple fsts' snds'
12101213
1214+ -- | Returns true if at least one array element satisfies the given predicate,
1215+ -- | iterating the array only as necessary and stopping as soon as the predicate
1216+ -- | yields true.
1217+ -- |
1218+ -- | ```purescript
1219+ -- | any (_ > 0) [] = False
1220+ -- | any (_ > 0) [-1, 0, 1] = True
1221+ -- | any (_ > 0) [-1, -2, -3] = False
1222+ -- | ```
1223+ foreign import any :: forall a. (a -> Boolean) -> Array a -> Boolean
1224+
1225+ -- | Returns true if all the array elements satisfy the given predicate.
1226+ -- | iterating the array only as necessary and stopping as soon as the predicate
1227+ -- | yields false.
1228+ -- |
1229+ -- | ```purescript
1230+ -- | all (_ > 0) [] = True
1231+ -- | all (_ > 0) [1, 2, 3] = True
1232+ -- | all (_ > 0) [-1, -2, -3] = False
1233+ -- | ```
1234+ foreign import all :: forall a. (a -> Boolean) -> Array a -> Boolean
1235+
12111236-- | Perform a fold using a monadic step function.
12121237-- |
12131238-- | ```purescript
0 commit comments