aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Chelleport/Utils.hs')
-rw-r--r--src/Chelleport/Utils.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/Chelleport/Utils.hs b/src/Chelleport/Utils.hs
new file mode 100644
index 0000000..5977039
--- /dev/null
+++ b/src/Chelleport/Utils.hs
@@ -0,0 +1,24 @@
+module Chelleport.Utils where
+
+import Data.List (nub)
+import Foreign.C (CInt)
+import Unsafe.Coerce (unsafeCoerce)
+
+intToCInt :: Int -> CInt
+intToCInt = unsafeCoerce
+
+findWithIndex :: (x -> Maybe r) -> Int -> [x] -> Maybe (Int, r)
+findWithIndex _predicate _index [] = Nothing
+findWithIndex predicate index (x : ls) =
+ case predicate x of
+ Just item -> Just (index, item)
+ Nothing -> findWithIndex predicate (index + 1) ls
+
+uniq :: (Eq a) => [a] -> [a]
+uniq = nub
+
+isEmpty :: [a] -> Bool
+isEmpty = null
+
+isNotEmpty :: [a] -> Bool
+isNotEmpty = not . isEmpty