From 36eb3a419ec9d0434f55456090e2845d4ac20b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 17 Jul 2022 15:36:23 +0200 Subject: Set of mergeable items --- src/Util.hs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Util.hs') 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 -- cgit v1.2.3