File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 4343
4444 findLastIndex :: forall a. (a -> Prim.Boolean) -> [a] -> Prim.Number
4545
46+ group :: forall a. (Eq a) => [a] -> [[a]]
47+
48+ groupBy :: forall a. (a -> a -> Prim.Boolean) -> [a] -> [[a]]
49+
4650 head :: forall a. [a] -> Maybe a
4751
4852 init :: forall a. [a] -> Maybe [a]
7579
7680 sortBy :: forall a. (a -> a -> Ordering) -> [a] -> [a]
7781
82+ span :: forall a. (a -> Prim.Boolean) -> [a] -> { rest :: [a], init :: [a] }
83+
7884 tail :: forall a. [a] -> Maybe [a]
7985
8086 take :: forall a. Prim.Number -> [a] -> [a]
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ module Data.Array
3030 , nubBy
3131 , sort
3232 , sortBy
33+ , group
34+ , groupBy
35+ , span
3336 ) where
3437
3538import Data.Maybe
@@ -283,6 +286,19 @@ foreign import sortJS
283286 \ };\
284287 \}" :: forall a . (a -> a -> Number ) -> [a ] -> [a ]
285288
289+ group :: forall a . (Eq a ) => [a ] -> [[a ]]
290+ group xs = groupBy (==) xs
291+
292+ groupBy :: forall a . (a -> a -> Boolean ) -> [a ] -> [[a ]]
293+ groupBy _ [] = []
294+ groupBy eq (x:xs) = case span (eq x) xs of
295+ {init = ys, rest = zs} -> (x:ys) : groupBy eq zs
296+
297+ span :: forall a . (a -> Boolean ) -> [a ] -> { init :: [a ], rest :: [a ] }
298+ span p (x:xs') | p x = case span p xs' of
299+ {init = ys, rest = zs} -> {init: (x:ys), rest: zs}
300+ span _ xs = {init: [] , rest: xs}
301+
286302instance functorArray :: Functor [] where
287303 (<$>) = map
288304
You can’t perform that action at this time.
0 commit comments