aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/Utils.hs
blob: 5977039bfc99833d39f7e3ace4edfd47a0365bf6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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