@@ -91,12 +91,14 @@ singleton :: forall a. a -> [a]
91
91
singleton a = [a]
92
92
93
93
-- | Get the first element in an array, or `Nothing` if the array is empty
94
+ -- |
95
+ -- | Running time: `O(1)`.
94
96
head :: forall a . [a ] -> Maybe a
95
97
head xs = xs !! 0
96
98
97
99
-- | Get the last element in an array, or `Nothing` if the array is empty
98
100
-- |
99
- -- | Running time: `O(n)` where `n` is the length of the array
101
+ -- | Running time: `O(1)`.
100
102
last :: forall a . [a ] -> Maybe a
101
103
last xs = xs !! (length xs - 1 )
102
104
@@ -268,7 +270,7 @@ delete = deleteBy (==)
268
270
269
271
infix 5 \\
270
272
271
- -- | Delete the first occurrence of each element in the second array from the first array,
273
+ -- | Delete the first occurrence of each element in the second array from the first array,
272
274
-- | creating a new array.
273
275
(\\) :: forall a . (Eq a ) => [a ] -> [a ] -> [a ]
274
276
(\\) xs ys = go xs ys
@@ -290,7 +292,7 @@ intersectBy eq xs ys = filter el xs
290
292
intersect :: forall a . (Eq a ) => [a ] -> [a ] -> [a ]
291
293
intersect = intersectBy (==)
292
294
293
- -- | Apply a function to each element in an array, and flatten the results
295
+ -- | Apply a function to each element in an array, and flatten the results
294
296
-- | into a single, new array.
295
297
foreign import concatMap
296
298
" function concatMap (f) {\
@@ -326,7 +328,7 @@ mapMaybe f = concatMap (maybe [] singleton <<< f)
326
328
catMaybes :: forall a . [Maybe a ] -> [a ]
327
329
catMaybes = concatMap (maybe [] singleton)
328
330
329
- -- | Filter an array, keeping the elements which satisfy a predicate function,
331
+ -- | Filter an array, keeping the elements which satisfy a predicate function,
330
332
-- | creating a new array.
331
333
foreign import filter
332
334
" function filter (f) {\
@@ -363,7 +365,7 @@ infix 8 ..
363
365
(..) :: Number -> Number -> [Number ]
364
366
(..) = range
365
367
366
- -- | Apply a function to pairs of elements at the same index in two arrays,
368
+ -- | Apply a function to pairs of elements at the same index in two arrays,
367
369
-- | collecting the results in a new array.
368
370
-- |
369
371
-- | If one array is longer, elements will be discarded from the longer array.
@@ -391,7 +393,7 @@ foreign import zipWith
391
393
nub :: forall a . (Eq a ) => [a ] -> [a ]
392
394
nub = nubBy (==)
393
395
394
- -- | Remove the duplicates from an array, where element equality is determined by the
396
+ -- | Remove the duplicates from an array, where element equality is determined by the
395
397
-- | specified equivalence relation, creating a new array.
396
398
nubBy :: forall a . (a -> a -> Boolean ) -> [a ] -> [a ]
397
399
nubBy _ [] = []
@@ -421,19 +423,19 @@ foreign import sortJS
421
423
\}" :: forall a . (a -> a -> Number ) -> [a ] -> [a ]
422
424
423
425
-- | Group equal, consecutive elements of an array into arrays.
424
- -- |
426
+ -- |
425
427
-- | For example,
426
- -- |
428
+ -- |
427
429
-- | ```purescript
428
430
-- | group [1,1,2,2,1] == [[1,1],[2,2],[1]]
429
431
-- | ```
430
432
group :: forall a . (Eq a ) => [a ] -> [[a ]]
431
433
group xs = groupBy (==) xs
432
434
433
435
-- | Sort and group the elements of an array into arrays.
434
- -- |
436
+ -- |
435
437
-- | For example,
436
- -- |
438
+ -- |
437
439
-- | ```purescript
438
440
-- | group [1,1,2,2,1] == [[1,1,1],[2,2]]
439
441
-- | ```
@@ -450,13 +452,13 @@ groupBy = go []
450
452
go acc op (x:xs) = let sp = span (op x) xs in
451
453
go ((x:sp.init):acc) op sp.rest
452
454
453
- -- | Split an array into two parts:
454
- -- |
455
+ -- | Split an array into two parts:
456
+ -- |
455
457
-- | 1. the longest initial subarray for which all element satisfy the specified predicate
456
458
-- | 2. the remaining elements
457
- -- |
459
+ -- |
458
460
-- | For example,
459
- -- |
461
+ -- |
460
462
-- | ```purescript
461
463
-- | span (\n -> n % 2 == 1) [1,3,2,4,5] == { init: [1,3], rest: [2,4,5] }
462
464
-- | ```
@@ -496,10 +498,10 @@ instance semigroupArray :: Semigroup [a] where
496
498
497
499
instance altArray :: Alt [] where
498
500
(<|>) = append
499
-
501
+
500
502
instance plusArray :: Plus [] where
501
503
empty = []
502
-
504
+
503
505
instance alternativeArray :: Alternative []
504
506
505
507
instance monadPlusArray :: MonadPlus []
0 commit comments