4 , empty, singleton, insert, remove
8 , union, intersect, diff
12{-| A set of unique values. The values can be any comparable type. This
13includes `Int`, `Float`, `Time`, `Char`, `String`, and tuples or lists
16Insert, remove, and query operations all take *O(log n)* time.
19@docs empty, singleton, insert, remove
25@docs union, intersect, diff
31@docs map, foldl, foldr, filter, partition
39type Set t = Dict.Dict t ()
41{-| Create an empty set. -}
45{-| Create a set with one value. -}
46singleton : comparable -> Set comparable
47singleton k = Dict.singleton k ()
49{-| Insert a value into a set. -}
50insert : comparable -> Set comparable -> Set comparable
51insert k = Dict.insert k ()
53{-| Remove a value from a set. If the value is not found, no changes are made.
55remove : comparable -> Set comparable -> Set comparable
58{-| Determine if a value is in a set. -}
59member : comparable -> Set comparable -> Bool
62{-| Get the union of two sets. Keep all values. -}
63union : Set comparable -> Set comparable -> Set comparable
66{-| Get the intersection of two sets. Keeps values that appear in both sets. -}
67intersect : Set comparable -> Set comparable -> Set comparable
68intersect = Dict.intersect
70{-| Get the difference between the first set and the second. Keeps values
71that do not appear in the second set. -}
72diff : Set comparable -> Set comparable -> Set comparable
75{-| Convert a set into a list. -}
76toList : Set comparable -> [comparable]
79{-| Convert a list into a set, removing any duplicates. -}
80fromList : [comparable] -> Set comparable
81fromList xs = List.foldl insert empty xs
83{-| Fold over the values in a set, in order from lowest to highest. -}
84foldl : (comparable -> b -> b) -> b -> Set comparable -> b
85foldl f b s = Dict.foldl (\k _ b -> f k b) b s
87{-| Fold over the values in a set, in order from highest to lowest. -}
88foldr : (comparable -> b -> b) -> b -> Set comparable -> b
89foldr f b s = Dict.foldr (\k _ b -> f k b) b s
91{-| Map a function onto a set, creating a new set with no duplicates. -}
92map : (comparable -> comparable') -> Set comparable -> Set comparable'
93map f s = fromList (List.map f (toList s))
95{-| Create a new set consisting only of elements which satisfy a predicate. -}
96filter : (comparable -> Bool) -> Set comparable -> Set comparable
97filter p set = Dict.filter (\k _ -> p k) set
99{-| Create two new sets; the first consisting of elements which satisfy a
100predicate, the second consisting of elements which do not. -}
101partition : (comparable -> Bool) -> Set comparable -> (Set comparable, Set comparable)
102partition p set = Dict.partition (\k _ -> p k) set
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list