From 1d07e554284593cdca804404d1d9f68a473ee986 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 15 Dec 2024 15:39:02 +0530 Subject: Refactor a bunch of stuff --- src/Chelleport/Utils.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/Chelleport/Utils.hs (limited to 'src/Chelleport/Utils.hs') 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 -- cgit v1.3.1