on 32efcfa help sign in
elk/core/Set.elm
48 lines 968 B history raw
2module Set (empty,singleton,insert,remove
3 ,member
4 ,foldl,foldr,map
5 ,union,intersect,diff
6 ,toList,fromList
7 ) where
9type Set t = Dict t ()
11empty : Set t
12empty = Dict.empty
14singleton : t -> Set t
15singleton k = Dict.singleton k ()
17insert : t -> Set t -> Set t
18insert k = Dict.insert k ()
20remove : t -> Set t -> Set t
21remove = Dict.remove
23member : t -> Set t -> Bool
24member = Dict.member
26union : Set t -> Set t -> Set t
27union = Dict.union
29intersect : Set t -> Set t -> Set t
30intersect = Dict.intersect
32diff : Set t -> Set t -> Set t
33diff = Dict.diff
35toList : Set t -> [t]
36toList = Dict.keys
38fromList : [t] -> Set t
39fromList = List.foldl (\k t -> Dict.insert k () t) empty
41foldl : (a -> b -> b) -> b -> Set a -> b
42foldl f = Dict.foldl (\k _ b -> f k b)
44foldr : (a -> b -> b) -> b -> Set a -> b
45foldr f = Dict.foldr (\k _ b -> f k b)
47map : (a -> b) -> Set a -> Set b
48map f = fromList . List.map f . toList