aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-15 15:39:02 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-15 15:45:37 +0530
commit1d07e554284593cdca804404d1d9f68a473ee986 (patch)
tree6f90288426699384cdb85cfdca4a036c3da1e51c /src/Chelleport/Utils.hs
parent0c6b8c83e8673b394914e1f824dfb887b762b0ee (diff)
downloadchelleport-1d07e554284593cdca804404d1d9f68a473ee986.tar.gz
chelleport-1d07e554284593cdca804404d1d9f68a473ee986.zip
Refactor a bunch of stuff
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