diff options
Diffstat (limited to 'src/Util.hs')
-rw-r--r-- | src/Util.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Util.hs b/src/Util.hs index 99d51f6..fe802e2 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -4,3 +4,11 @@ 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 |