summaryrefslogtreecommitdiff
path: root/src/Util.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2023-09-19 20:49:58 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2023-10-19 21:37:01 +0200
commit61808c8cd7b30ceaf9915e72d734c4d095ff67d6 (patch)
tree7897848d5e61747c5ccf4136bc77c9d9490d1c52 /src/Util.hs
parent967cb4587c1af9fb53bfd1a30d007877d16e03fa (diff)
Identity extension data
Diffstat (limited to 'src/Util.hs')
-rw-r--r--src/Util.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Util.hs b/src/Util.hs
index fe802e2..c69adee 100644
--- a/src/Util.hs
+++ b/src/Util.hs
@@ -12,3 +12,26 @@ mergeBy cmp (x : xs) (y : ys) = case cmp x y of
GT -> y : mergeBy cmp (x : xs) ys
mergeBy _ xs [] = xs
mergeBy _ [] ys = ys
+
+mergeUniqBy :: (a -> a -> Ordering) -> [a] -> [a] -> [a]
+mergeUniqBy cmp (x : xs) (y : ys) = case cmp x y of
+ LT -> x : mergeBy cmp xs (y : ys)
+ EQ -> x : mergeBy cmp xs ys
+ GT -> y : mergeBy cmp (x : xs) ys
+mergeUniqBy _ xs [] = xs
+mergeUniqBy _ [] ys = ys
+
+mergeUniq :: Ord a => [a] -> [a] -> [a]
+mergeUniq = mergeUniqBy compare
+
+diffSorted :: Ord a => [a] -> [a] -> [a]
+diffSorted (x:xs) (y:ys) | x < y = x : diffSorted xs (y:ys)
+ | x > y = diffSorted (x:xs) ys
+ | otherwise = diffSorted xs (y:ys)
+diffSorted xs _ = xs
+
+intersectsSorted :: Ord a => [a] -> [a] -> Bool
+intersectsSorted (x:xs) (y:ys) | x < y = intersectsSorted xs (y:ys)
+ | x > y = intersectsSorted (x:xs) ys
+ | otherwise = True
+intersectsSorted _ _ = False