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