summaryrefslogtreecommitdiff
path: root/src/Util.hs
blob: fe802e2f64c7a5bb4b4668d073565da6d4d05b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Util where

uniq :: Eq a => [a] -> [a]
uniq (x:y:xs) | x == y    = uniq (x:xs)
              | otherwise = x : uniq (y:xs)
uniq xs = xs

mergeBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
mergeBy cmp (x : xs) (y : ys) = case cmp x y of
                                     LT -> x : mergeBy cmp xs (y : ys)
                                     EQ -> x : y : mergeBy cmp xs ys
                                     GT -> y : mergeBy cmp (x : xs) ys
mergeBy _ xs [] = xs
mergeBy _ [] ys = ys