never executed always true always false
1 -- | A tiny wrapper around 'IntSet.IntSet' for representing sets of 'Enum'
2 -- things.
3 module GHC.Data.EnumSet
4 ( EnumSet
5 , member
6 , insert
7 , delete
8 , toList
9 , fromList
10 , empty
11 , difference
12 ) where
13
14 import GHC.Prelude
15
16 import qualified Data.IntSet as IntSet
17
18 newtype EnumSet a = EnumSet IntSet.IntSet
19
20 member :: Enum a => a -> EnumSet a -> Bool
21 member x (EnumSet s) = IntSet.member (fromEnum x) s
22
23 insert :: Enum a => a -> EnumSet a -> EnumSet a
24 insert x (EnumSet s) = EnumSet $ IntSet.insert (fromEnum x) s
25
26 delete :: Enum a => a -> EnumSet a -> EnumSet a
27 delete x (EnumSet s) = EnumSet $ IntSet.delete (fromEnum x) s
28
29 toList :: Enum a => EnumSet a -> [a]
30 toList (EnumSet s) = map toEnum $ IntSet.toList s
31
32 fromList :: Enum a => [a] -> EnumSet a
33 fromList = EnumSet . IntSet.fromList . map fromEnum
34
35 empty :: EnumSet a
36 empty = EnumSet IntSet.empty
37
38 difference :: EnumSet a -> EnumSet a -> EnumSet a
39 difference (EnumSet a) (EnumSet b) = EnumSet (IntSet.difference a b)