elm-lang/core/3.0.0

NOTE: this package moved to elm/core

NOTE: this package is not compatible with Elm 0.19.1

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.

Insert, remove, and query operations all take O(log n) time. Set equality with (==) is unreliable and should not be used.

Sets

type Set t

Represents a set of unique values. So (Set Int) is a set of integers and (Set String) is a set of strings.

Build

empty : Set a

Create an empty set.

singleton : comparable -> Set comparable

Create a set with one value.

insert : comparable -> Set comparable -> Set comparable

Insert a value into a set.

remove : comparable -> Set comparable -> Set comparable

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

Query

isEmpty : Set a -> Bool

Determine if a set is empty.

member : comparable -> Set comparable -> Bool

Determine if a value is in a set.

size : Set a -> Int

Determine the number of elements in a set.

Combine

union : Set comparable -> Set comparable -> Set comparable

Get the union of two sets. Keep all values.

intersect : Set comparable -> Set comparable -> Set comparable

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

diff : Set comparable -> Set comparable -> Set comparable

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

Lists

toList : Set comparable -> List comparable

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

fromList : List comparable -> Set comparable

Convert a list into a set, removing any duplicates.

Transform

map : (comparable -> comparable_) -> Set comparable -> Set comparable_

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

foldl : (comparable -> b -> b) -> b -> Set comparable -> b

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

foldr : (comparable -> b -> b) -> b -> Set comparable -> b

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

filter : (comparable -> Bool) -> Set comparable -> Set comparable

Create a new set consisting only of elements which satisfy a predicate.

(comparable -> Bool)
-> Set comparable
-> ( Set comparable, Set comparable )

Create two new sets; the first consisting of elements which satisfy a predicate, the second consisting of elements which do not.