Skip to content

Commit 7bcd572

Browse files
committed
Update documentation and tests
1 parent a22f493 commit 7bcd572

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

src/Data/Array.purs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,10 +1195,26 @@ unzip xs =
11951195
snds' <- STA.unsafeFreeze snds
11961196
pure $ Tuple fsts' snds'
11971197

1198-
-- | Returns true if at least one array element satisfy the given predicate.
1198+
-- | Returns true if at least one array element satisfies the given predicate,
1199+
-- | iterating the array only as necessary and stopping as soon as the predicate
1200+
-- | yields true.
1201+
-- |
1202+
-- | ```purescript
1203+
-- | any (_ > 0) [] = False
1204+
-- | any (_ > 0) [-1, 0, 1] = True
1205+
-- | any (_ > 0) [-1, -2, -3] = False
1206+
-- | ```
11991207
foreign import any :: forall a. (a -> Boolean) -> Array a -> Boolean
12001208

12011209
-- | Returns true if all the array elements satisfy the given predicate.
1210+
-- | iterating the array only as necessary and stopping as soon as the predicate
1211+
-- | yields false.
1212+
-- |
1213+
-- | ```purescript
1214+
-- | all (_ > 0) [] = True
1215+
-- | all (_ > 0) [1, 2, 3] = True
1216+
-- | all (_ > 0) [-1, -2, -3] = False
1217+
-- | ```
12021218
foreign import all :: forall a. (a -> Boolean) -> Array a -> Boolean
12031219

12041220
-- | Perform a fold using a monadic step function.

test/Test/Data/Array.purs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ testArray = do
416416
assert $ A.unzip [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"] == Tuple [1, 2, 3] ["a", "b", "c"]
417417

418418
log "any should return true if at least one array element satisfy the given predicate"
419-
assert $ not $ A.any (_ > 2) []
420-
assert $ A.any (_ > 2) [1, 2, 3]
421-
assert $ not $ A.any (_ > 3) [1, 2, 3]
419+
assert $ not $ A.any (_ > 0) []
420+
assert $ A.any (_ > 0) [-1, 0, 1]
421+
assert $ not $ A.any (_ > 0) [-1, -2, -3]
422422

423423
log "all should return true if all the array elements satisfy the given predicate"
424424
assert $ A.all (_ > 0) []
425425
assert $ A.all (_ > 0) [1, 2, 3]
426-
assert $ not $ A.all (_ > 1) [1, 2, 3]
426+
assert $ not $ A.all (_ > 0) [-1, -2, -3]
427427

428428
log "foldM should perform a fold using a monadic step function"
429429
assert $ A.foldM (\x y -> Just (x + y)) 0 (A.range 1 10) == Just 55

test/Test/Data/Array/NonEmpty.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ testNonEmptyArray = do
286286
assert $ NEA.unzip (fromArray [Tuple 1 "a", Tuple 2 "b", Tuple 3 "c"]) == Tuple (fromArray [1, 2, 3]) (fromArray ["a", "b", "c"])
287287

288288
log "any should return true if at least one array element satisfy the given predicate"
289-
assert $ NEA.any (_ > 2) $ fromArray [1, 2, 3]
290-
assert $ not $ NEA.any (_ > 3) $ fromArray [1, 2, 3]
289+
assert $ NEA.any (_ > 0) $ fromArray [-1, 0, 1]
290+
assert $ not $ NEA.any (_ > 0) $ fromArray [-1, -2, -3]
291291

292292
log "all should return true if all the array elements satisfy the given predicate"
293293
assert $ NEA.all (_ > 0) $ fromArray [1, 2, 3]
294-
assert $ not $ NEA.all (_ > 1) $ fromArray [1, 2, 3]
294+
assert $ not $ NEA.all (_ > 0) $ fromArray [-1, -2, -3]
295295

296296
log "fromFoldable"
297297
for_ (fromArray [[], [1], [1,2], [1,2,3,4,5]]) \xs -> do

0 commit comments

Comments
 (0)