bburdette/typed-collections/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

TSet

A set of unique values. Unlike in the elm Set, the elements can be any type that can be converted to an elm 'comparable'.

This is helpful if you have values that are really just a comparable underneath, but you want to keep them separate using the type system. For instance

type Kilos = Kilos Float type Pounds = Pounds Float

Create a TSet with the empty function, which takes two converter functions as arguments. It can be convenient to create a canonical empty TSet for a certain type:

emptyKiloSet = TSet.empty ((Kilos n) -> n) Kilos

Then to do the equivalent of fromList:

TSet.insertList emptyKiloSet mykilolist

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

Sets

type TSet k comparable

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

Build

empty : (k -> comparable) -> (comparable -> k) -> TSet k comparable

Create an empty set.

clear : TSet k comparable -> TSet k comparable

remove all values from the set.

insert : k -> TSet k comparable -> TSet k comparable

Insert a value into a set.

remove : k -> TSet k comparable -> TSet k comparable

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

Query

isEmpty : TSet k comparable -> Bool

Determine if a set is empty.

member : k -> TSet k comparable -> Bool

Determine if a value is in a set.

size : TSet k comparable -> Int

Determine the number of elements in a set.

Combine

union : TSet k comparable -> TSet k comparable -> TSet k comparable

Get the union of two sets. Keep all values.

intersect : TSet k comparable -> TSet k comparable -> TSet k comparable

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

diff : TSet k comparable -> TSet k comparable -> TSet k comparable

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

Lists

toList : TSet k comparable -> List k

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

insertList : TSet k comparable -> List k -> TSet k comparable

Insert a list of values into a set.

Transform

(k -> k2)
-> TSet k comparable
-> TSet k2 comparable2
-> TSet k2 comparable2

Map a function onto a set, inserting into a second set.

foldl : (k -> b -> b) -> b -> TSet k comparable -> b

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

foldr : (k -> b -> b) -> b -> TSet k comparable -> b

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

filter : (k -> Bool) -> TSet k comparable -> TSet k comparable

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

(k -> Bool)
-> TSet k comparable
-> ( TSet k comparable, TSet k comparable )

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