@@ -117,6 +117,9 @@ module Data.Array
117
117
, zip
118
118
, unzip
119
119
120
+ , any
121
+ , all
122
+
120
123
, foldM
121
124
, foldRecM
122
125
@@ -136,7 +139,7 @@ import Data.Array.NonEmpty.Internal (NonEmptyArray(..))
136
139
import Data.Array.ST as STA
137
140
import Data.Array.ST.Iterator as STAI
138
141
import 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
140
143
import Data.Maybe (Maybe (..), maybe , isJust , fromJust , isNothing )
141
144
import Data.Traversable (sequence , traverse )
142
145
import Data.Tuple (Tuple (..), fst , snd )
@@ -1051,7 +1054,7 @@ nubByEq :: forall a. (a -> a -> Boolean) -> Array a -> Array a
1051
1054
nubByEq eq xs = ST .run do
1052
1055
arr <- STA .empty
1053
1056
ST .foreach xs \x -> do
1054
- e <- not <<< Exports . any (_ `eq` x) <$> (STA .unsafeFreeze arr)
1057
+ e <- not <<< any (_ `eq` x) <$> (STA .unsafeFreeze arr)
1055
1058
when e $ void $ STA .push x arr
1056
1059
STA .unsafeFreeze arr
1057
1060
@@ -1208,6 +1211,28 @@ unzip xs =
1208
1211
snds' <- STA .unsafeFreeze snds
1209
1212
pure $ Tuple fsts' snds'
1210
1213
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
+
1211
1236
-- | Perform a fold using a monadic step function.
1212
1237
-- |
1213
1238
-- | ```purescript
0 commit comments