Safe Haskell | None |
---|---|
Language | Haskell2010 |
A set of unique values. The values can be any comparable type. This
includes Int
, Float
, Time
, Char
, String
, and tuples or lists
of comparable types.
Insert, remove, and query operations all take *O(log n)* time.
Synopsis
- type Set t = Set t
- empty :: Set a
- singleton :: comparable -> Set comparable
- insert :: Ord comparable => comparable -> Set comparable -> Set comparable
- remove :: Ord comparable => comparable -> Set comparable -> Set comparable
- isEmpty :: Set a -> Bool
- member :: Ord comparable => comparable -> Set comparable -> Bool
- size :: Set a -> Int
- union :: Ord comparable => Set comparable -> Set comparable -> Set comparable
- intersect :: Ord comparable => Set comparable -> Set comparable -> Set comparable
- diff :: Ord comparable => Set comparable -> Set comparable -> Set comparable
- toList :: Set a -> List a
- fromList :: Ord comparable => List comparable -> Set comparable
- map :: Ord comparable2 => (comparable -> comparable2) -> Set comparable -> Set comparable2
- foldl :: (a -> b -> b) -> b -> Set a -> b
- foldr :: (a -> b -> b) -> b -> Set a -> b
- filter :: (comparable -> Bool) -> Set comparable -> Set comparable
- partition :: (comparable -> Bool) -> Set comparable -> (Set comparable, Set comparable)
Sets
Represents a set of unique values. So (Set Int)
is a set of integers and
(Set String)
is a set of strings.
Build
insert :: Ord comparable => comparable -> Set comparable -> Set comparable Source #
Insert a value into a set.
remove :: Ord comparable => comparable -> Set comparable -> Set comparable Source #
Remove a value from a set. If the value is not found, no changes are made.
Query
member :: Ord comparable => comparable -> Set comparable -> Bool Source #
Determine if a value is in a set.
Combine
union :: Ord comparable => Set comparable -> Set comparable -> Set comparable Source #
Get the union of two sets, preferring the first set when equal elements are encountered.
In Elm it's not possible to have two comparable elements that are not equal, but it is possible in Haskell.
intersect :: Ord comparable => Set comparable -> Set comparable -> Set comparable Source #
Get the intersection of two sets, preferring the first set when equal elements are encountered.
In Elm it's not possible to have two comparable elements that are not equal, but it is possible in Haskell.
diff :: Ord comparable => Set comparable -> Set comparable -> Set comparable Source #
Get the difference between the first set and the second. Keeps values that do not appear in the second set.
Lists
fromList :: Ord comparable => List comparable -> Set comparable Source #
Convert a list into a set, removing any duplicates.
Transform
map :: Ord comparable2 => (comparable -> comparable2) -> Set comparable -> Set comparable2 Source #
Map a function onto a set, creating a new set with no duplicates.
foldl :: (a -> b -> b) -> b -> Set a -> b Source #
Fold over the values in a set, in order from lowest to highest.
foldr :: (a -> b -> b) -> b -> Set a -> b Source #
Fold over the values in a set, in order from highest to lowest.
filter :: (comparable -> Bool) -> Set comparable -> Set comparable Source #
Only keep elements that pass the given test.
import Set exposing (Set) numbers : Set Int numbers = Set.fromList [-2,-1,0,1,2] positives : Set Int positives = Set.filter (\x -> x > 0) numbers -- positives == Set.fromList [1,2]