diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-17 15:36:23 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2022-07-17 21:19:23 +0200 |
commit | 36eb3a419ec9d0434f55456090e2845d4ac20b58 (patch) | |
tree | f32d3ff500863a3528c1b4008b736c1cc77fb084 /src/Util.hs | |
parent | 1986e8f51b992edcc675e76edd5d1f85522b8e6d (diff) |
Set of mergeable items
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 |