Module

Data.Set.NonEmpty

Package
purescript-ordered-collections
Repository
purescript/purescript-ordered-collections

#NonEmptySet Source

newtype NonEmptySet a

NonEmptySet a represents a non-empty set of values of type a

Instances

#singleton Source

singleton :: forall a. a -> NonEmptySet a

Create a set with one element.

#cons Source

cons :: forall a. Ord a => a -> Set a -> NonEmptySet a

Creates a NonEmptySet from an item and a Set.

#fromSet Source

fromSet :: forall a. Set a -> Maybe (NonEmptySet a)

Attempts to create a non-empty set from a possibly-empty set.

#fromFoldable Source

fromFoldable :: forall f a. Foldable f => Ord a => f a -> Maybe (NonEmptySet a)

Create a set from a foldable structure.

#fromFoldable1 Source

fromFoldable1 :: forall f a. Foldable1 f => Ord a => f a -> NonEmptySet a

Create a set from a non-empty foldable structure.

#toSet Source

toSet :: forall a. NonEmptySet a -> Set a

Forgets the non-empty property of a set, giving a normal possibly-empty set.

#toUnfoldable Source

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

Convert a set to an unfoldable structure.

#toUnfoldable1 Source

toUnfoldable1 :: forall f a. Unfoldable1 f => NonEmptySet a -> f a

Convert a set to a non-empty unfoldable structure.

#map Source

map :: forall a b. Ord b => (a -> b) -> NonEmptySet a -> NonEmptySet b

Maps over the values in a set.

This operation is not structure-preserving for sets, so is not a valid Functor. An example case: mapping const x over a set with n > 0 elements will result in a set with one element.

#member Source

member :: forall a. Ord a => a -> NonEmptySet a -> Boolean

Test if a value is a member of a set.

#insert Source

insert :: forall a. Ord a => a -> NonEmptySet a -> NonEmptySet a

Insert a value into a set.

#delete Source

delete :: forall a. Ord a => a -> NonEmptySet a -> Maybe (NonEmptySet a)

Delete a value from a non-empty set. If this would empty the set, the result is Nothing.

#size Source

size :: forall a. NonEmptySet a -> Int

Find the size of a set.

#min Source

min :: forall a. NonEmptySet a -> a

The minimum value in the set.

#max Source

max :: forall a. NonEmptySet a -> a

The maximum value in the set.

#unionSet Source

unionSet :: forall a. Ord a => Set a -> NonEmptySet a -> NonEmptySet a

Form the union of a set and the non-empty set.

#difference Source

difference :: forall a. Ord a => NonEmptySet a -> NonEmptySet a -> Maybe (NonEmptySet a)

Form the set difference. Nothing if the first is a subset of the second.

#subset Source

subset :: forall a. Ord a => NonEmptySet a -> NonEmptySet a -> Boolean

True if and only if every element in the first set is an element of the second set.

#properSubset Source

properSubset :: forall a. Ord a => NonEmptySet a -> NonEmptySet a -> Boolean

True if and only if the first set is a subset of the second set and the sets are not equal.

#intersection Source

intersection :: forall a. Ord a => NonEmptySet a -> NonEmptySet a -> Maybe (NonEmptySet a)

The set of elements which are in both the first and second set. Nothing if the sets are disjoint.

#filter Source

filter :: forall a. Ord a => (a -> Boolean) -> NonEmptySet a -> Set a

Filter out those values of a set for which a predicate on the value fails to hold.

#mapMaybe Source

mapMaybe :: forall a b. Ord b => (a -> Maybe b) -> NonEmptySet a -> Set b

Applies a function to each value in a set, discarding entries where the function returns Nothing.