YuyaAizawa / list-wrapper / ListWrapper.Set

A set implementation using List. The elements can be any type includes recodes and custom type. This module provides all functions does Set, except 'foldl', 'foldr', 'merge'.

Insert, remove, and query operations all take O(n) time. Only for a few elements.

To determine equality, use 'eq' instead of '(==)'.

Sets


type Set e

A set of unique values.

Build

empty : Set e

Create an empty set.

singleton : e -> Set e

Create a set with one value.

insert : e -> Set e -> Set e

Insert a value into a set.

remove : e -> Set e -> Set e

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

Query

isEmpty : Set e -> Basics.Bool

Determine if a set is empty.

member : e -> Set e -> Basics.Bool

Determine if a value is in a set.

size : Set e -> Basics.Int

Determine the number of elements in a set.

eq : Set e -> Set e -> Basics.Bool

Determine if given two dictionary are the same.

Combine

union : Set e -> Set e -> Set e

Get the union of two sets. Keep all values.

intersect : Set e -> Set e -> Set e

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

diff : Set e -> Set e -> Set e

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

Lists

toList : Set a -> List a

Convert a set into a list. The order is not Fixed.

fromList : List e -> Set e

Convert a list into a set, removing any duplicates.

Transform

map : (e1 -> e2) -> Set e1 -> Set e2

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

fold : (e -> a -> a) -> a -> Set e -> a

Fold over the key-value pairs in a dictionary. The order is not fixed.

filter : (e -> Basics.Bool) -> Set e -> Set e

Only keep elements that pass the given test.

partition : (e -> Basics.Bool) -> Set e -> ( Set e, Set e )

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.