Module

Data.HashSet

Package
purescript-unordered-collections
Repository
fehrenbach/purescript-unordered-collections

#HashSet Source

newtype HashSet a

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

a needs to be Hashable for most operations.

Instances

#empty Source

empty :: forall a. HashSet a

The empty set.

#singleton Source

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

The singleton set.

#insert Source

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

Insert a value into a set.

#member Source

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

Test whether a value is in a set.

#delete Source

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

Remove a value from a set.

#map Source

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 Source

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 Source

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 Source

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

Union two sets.

#intersection Source

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

Intersect two sets.

#difference Source

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 Source

size :: forall a. HashSet a -> Int

Count the number of elements.

Also known as cardinality, or length.

#fromFoldable Source

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

Create a set from a foldable structure.

#toArray Source

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.