@@ -91,12 +91,14 @@ singleton :: forall a. a -> [a]
9191singleton a = [a]
9292
9393-- | Get the first element in an array, or `Nothing` if the array is empty
94+ -- |
95+ -- | Running time: `O(1)`.
9496head :: forall a . [a ] -> Maybe a
9597head xs = xs !! 0
9698
9799-- | Get the last element in an array, or `Nothing` if the array is empty
98100-- |
99- -- | Running time: `O(n)` where `n` is the length of the array
101+ -- | Running time: `O(1)`.
100102last :: forall a . [a ] -> Maybe a
101103last xs = xs !! (length xs - 1 )
102104
@@ -268,7 +270,7 @@ delete = deleteBy (==)
268270
269271infix 5 \\
270272
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,
272274-- | creating a new array.
273275(\\) :: forall a . (Eq a ) => [a ] -> [a ] -> [a ]
274276(\\) xs ys = go xs ys
@@ -290,7 +292,7 @@ intersectBy eq xs ys = filter el xs
290292intersect :: forall a . (Eq a ) => [a ] -> [a ] -> [a ]
291293intersect = intersectBy (==)
292294
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
294296-- | into a single, new array.
295297foreign import concatMap
296298 " function concatMap (f) {\
@@ -326,7 +328,7 @@ mapMaybe f = concatMap (maybe [] singleton <<< f)
326328catMaybes :: forall a . [Maybe a ] -> [a ]
327329catMaybes = concatMap (maybe [] singleton)
328330
329- -- | Filter an array, keeping the elements which satisfy a predicate function,
331+ -- | Filter an array, keeping the elements which satisfy a predicate function,
330332-- | creating a new array.
331333foreign import filter
332334 " function filter (f) {\
@@ -363,7 +365,7 @@ infix 8 ..
363365(..) :: Number -> Number -> [Number ]
364366(..) = range
365367
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,
367369-- | collecting the results in a new array.
368370-- |
369371-- | If one array is longer, elements will be discarded from the longer array.
@@ -391,7 +393,7 @@ foreign import zipWith
391393nub :: forall a . (Eq a ) => [a ] -> [a ]
392394nub = nubBy (==)
393395
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
395397-- | specified equivalence relation, creating a new array.
396398nubBy :: forall a . (a -> a -> Boolean ) -> [a ] -> [a ]
397399nubBy _ [] = []
@@ -421,19 +423,19 @@ foreign import sortJS
421423 \}" :: forall a . (a -> a -> Number ) -> [a ] -> [a ]
422424
423425-- | Group equal, consecutive elements of an array into arrays.
424- -- |
426+ -- |
425427-- | For example,
426- -- |
428+ -- |
427429-- | ```purescript
428430-- | group [1,1,2,2,1] == [[1,1],[2,2],[1]]
429431-- | ```
430432group :: forall a . (Eq a ) => [a ] -> [[a ]]
431433group xs = groupBy (==) xs
432434
433435-- | Sort and group the elements of an array into arrays.
434- -- |
436+ -- |
435437-- | For example,
436- -- |
438+ -- |
437439-- | ```purescript
438440-- | group [1,1,2,2,1] == [[1,1,1],[2,2]]
439441-- | ```
@@ -450,13 +452,13 @@ groupBy = go []
450452 go acc op (x:xs) = let sp = span (op x) xs in
451453 go ((x:sp.init):acc) op sp.rest
452454
453- -- | Split an array into two parts:
454- -- |
455+ -- | Split an array into two parts:
456+ -- |
455457-- | 1. the longest initial subarray for which all element satisfy the specified predicate
456458-- | 2. the remaining elements
457- -- |
459+ -- |
458460-- | For example,
459- -- |
461+ -- |
460462-- | ```purescript
461463-- | span (\n -> n % 2 == 1) [1,3,2,4,5] == { init: [1,3], rest: [2,4,5] }
462464-- | ```
@@ -496,10 +498,10 @@ instance semigroupArray :: Semigroup [a] where
496498
497499instance altArray :: Alt [] where
498500 (<|>) = append
499-
501+
500502instance plusArray :: Plus [] where
501503 empty = []
502-
504+
503505instance alternativeArray :: Alternative []
504506
505507instance monadPlusArray :: MonadPlus []
0 commit comments