# Set

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.

Set, remove, and query operations all take *O(log n)* time.

Represents a set of unique values. So `(Set Int)`

is a set of integers and
`(Set String)`

is a set of strings.

Create an empty set.

Create a set with one value.

Set a value into a set.

Remove a value from a set. If the value is not found, no changes are made.

## Query

Determine if a set is empty.

Determine if a value is in a set.

Determine the number of elements in a set.

Get the first element of the set.

Get the last element of the set.

Find the first value that passes the test.

Find the last value that passes the test.

Checks if any value in the set passes the test.

Checks if all values in the set passes the test.

## Combine

Get the union of two sets. Keep all values.

Get the intersection of two sets. Keeps values that appear in both sets.

Get the difference between the first set and the second. Keeps values that do not appear in the second set.

## Arrays

Convert a set into a list, sorted from lowest to highest.

Convert a list into a set, removing any duplicates.

## Transform

Map a function onto a set, creating a new set with no duplicates.

Fold over the values in a set, in order from lowest to highest.

Fold over the values in a set, in order from highest to lowest.

Only keep elements that pass the given test.

```
import Set exposing (Set)
numbers : Set Int
numbers =
Set.fromArray [ -2, -1, 0, 1, 2 ]
positives : Set Int
positives =
Set.filter (\x -> x > 0) numbers
-- positives == Set.fromArray [1,2]
```

Filter out unwanted results of a map operation.

```
import Set
strings : Set String
strings =
Set.fromArray [ "3", "not a number", "-5" ]
numbers : Set Int
numbers =
Set.filterMap String.toInt strings
-- numbers == Set.fromArray [ 3, -5 ]
```

Create two new sets. The first contains all the elements that passed the given test, and the second contains all the elements that did not.