Module

Data.HashSet

#HashSet

newtype HashSet a

A HashSet a is a set with elements of type a.

a needs to be Hashable for most operations.

Instances

#empty

empty :: forall a. HashSet a

The empty set.

#singleton

singleton :: forall a. Hashable a => a -> HashSet a

The singleton set.

#insert

insert :: forall a. Hashable a => a -> HashSet a -> HashSet a

Insert a value into a set.

#member

member :: forall a. Hashable a => a -> HashSet a -> Boolean

Test whether a value is in a set.

#delete

delete :: forall a. Hashable a => a -> HashSet a -> HashSet a

Remove a value from a set.

#map

map :: forall a b. Hashable b => (a -> b) -> HashSet a -> HashSet b

Construct a new set by applying a function to each element of an input set.

If distinct inputs map to the same output, this changes the cardinality of the set, therefore hash set is not a Functor. Also, the order in which elements appear in the new set is entirely dependent on the hash function for type b.

#filter

filter :: forall a. (a -> Boolean) -> HashSet a -> HashSet a

Remove all elements from the set for which the predicate does not hold.

filter (const false) s == empty

#mapMaybe

mapMaybe :: forall a b. Hashable b => (a -> Maybe b) -> HashSet a -> HashSet b

Map a function over a set, keeping only the Just values.

#union

union :: forall a. Hashable a => HashSet a -> HashSet a -> HashSet a

Union two sets.

#unions

unions :: forall f a. Foldable f => Hashable a => f (HashSet a) -> HashSet a

Union a collection of sets.

#intersection

intersection :: forall a. Hashable a => HashSet a -> HashSet a -> HashSet a

Intersect two sets.

#difference

difference :: forall a. Hashable a => HashSet a -> HashSet a -> HashSet a

Difference of two sets.

Also known as set minus or relative complement. Returns a set of all elements of the left set that are not in the right set.

#size

size :: forall a. HashSet a -> Int

Count the number of elements.

Also known as cardinality, or length.

#isEmpty

isEmpty :: forall a. HashSet a -> Boolean

Test whether a set is empty.

isEmpty s == (s == empty)

#fromArray

fromArray :: forall a. Hashable a => Array a -> HashSet a

Turn an array into a hash set.

This uses a mutable hash map internally and is faster than fromFoldable.

#fromFoldable

fromFoldable :: forall f a. Foldable f => Hashable a => f a -> HashSet a

Create a set from a foldable structure.

#fromMap

fromMap :: forall a. HashMap a Unit -> HashSet a

#toArray

toArray :: forall a. HashSet a -> Array a

Turn a set into an array of its elments in no particular order.

To delete duplicates in an array, consider using nubHash from Data.HashMap instead of toArray <<< fromFoldable.

#toMap

toMap :: forall a. HashSet a -> HashMap a Unit

#toUnfoldable

toUnfoldable :: forall f a. Unfoldable f => HashSet a -> f a

Turn a set into an unfoldable functor.

You probably want to use toArray instead, especially if you want to get an array out.

Modules