joneshf/elm-tagged/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

Tagged.Set

A module that allows tagging sets, while maintaining an API parallel to Set.

A common idea is wanting to store a value that is not comparable in Set a. Since we can't currently do that there are many different ways to address the problem. One way to solve that problem is to use a type level assertion.

Rather than holding on to an entirely different type for the values and threading a comparison function through, we can just tell elm that we'd like to tag the Set a at compile time. Doing so allows us to reuse the underlying behavior of the Set a with very little runtime overhead. Most functions here are simple wrappers to refine the types without modifying the values.

type alias TaggedSet a comparable =
Tagged a (Set comparable)

A set that tags the values with an additional constraint.

The constraint is phantom in that it doesn't show up at runtime.

Build

empty : TaggedSet k comparable

Create an empty set.

singleton : Tagged k comparable -> TaggedSet k comparable

Create a set with one value.

Tagged k comparable
-> TaggedSet k comparable
-> TaggedSet k comparable

Insert a value pair into a set.

Tagged k comparable
-> TaggedSet k comparable
-> TaggedSet k comparable

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

Query

isEmpty : TaggedSet k c -> Bool

Determine if a set is empty.

member : Tagged k comparable -> TaggedSet k comparable -> Bool

Determine if a value is in a set.

size : TaggedSet k c -> Int

Determine the number of values in a set.

Lists

toUntaggedList : TaggedSet k comparable -> List comparable

Convert a set into a sorted list of untagged values.

fromUntaggedList : List comparable -> TaggedSet k comparable

Convert an untagged list into a set.

toList : TaggedSet k comparable -> List (Tagged k comparable)

Convert a set into a sorted list of tagged values.

fromList : List (Tagged k comparable) -> TaggedSet k comparable

Convert a list into a set.

Transform

map :
(Tagged k comparable -> comparable2)
-> TaggedSet k comparable
-> TaggedSet k comparable2

Apply a function to all values in a set.

foldl : (Tagged k comparable -> b -> b) -> b -> TaggedSet k comparable -> b

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

foldr : (Tagged k comparable -> b -> b) -> b -> TaggedSet k comparable -> b

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

(Tagged k comparable -> Bool)
-> TaggedSet k comparable
-> TaggedSet k comparable

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

(Tagged k comparable -> Bool)
-> TaggedSet k comparable
-> ( TaggedSet k comparable, TaggedSet k comparable )

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

Combine

TaggedSet k comparable
-> TaggedSet k comparable
-> TaggedSet k comparable

Get the union of two sets. Keep all values.

TaggedSet k comparable
-> TaggedSet k comparable
-> TaggedSet k comparable

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

TaggedSet k comparable
-> TaggedSet k comparable
-> TaggedSet k comparable

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