summaryrefslogtreecommitdiff
path: root/utility.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-06-16 23:24:47 +0200
committertomsmeding <tom.smeding@gmail.com>2016-06-16 23:24:47 +0200
commitdd3db844dd49451f28d044cd1d2fd71430d73686 (patch)
treecd76d7ad6efbf2d2e4760695d39cb48bb479a936 /utility.hs
Initial
Diffstat (limited to 'utility.hs')
-rw-r--r--utility.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/utility.hs b/utility.hs
new file mode 100644
index 0000000..c442f80
--- /dev/null
+++ b/utility.hs
@@ -0,0 +1,20 @@
+module Utility where
+
+import Data.List
+
+--if any of the predicates returns true, options returns true
+options :: [a -> Bool] -> a -> Bool
+options l x = any id [f x | f <- l]
+
+fixpoint :: (Eq a) => (a -> a) -> a -> a
+fixpoint f x = let fx = f x in if fx == x then x else fixpoint f fx
+
+setcompareBy :: (a -> a -> Bool) -> [a] -> [a] -> Bool
+setcompareBy _ [] [] = True
+setcompareBy _ [] _ = False
+setcompareBy _ _ [] = False
+setcompareBy p a@(x:xs) b = length a == length b && setcompareBy p xs (deleteBy p x b)
+
+deleteIndex :: Int -> [a] -> [a]
+deleteIndex 0 (_:xs) = xs
+deleteIndex i (x:xs) | i > 0 = x : deleteIndex (i-1) xs