A non-empty (by construction) set of values a. At least one value
exists in an NESet a at all times.
Functions that take an NESet can safely operate on it with the assumption that it has at least one item.
Functions that return an NESet provide an assurance that the result has at least one item.
Data.Set.NonEmpty re-exports the API of Data.Set, faithfully reproducing asymptotics, typeclass constraints, and semantics. Functions that ensure that input and output sets are both non-empty (like insert) return NESet, but functions that might potentially return an empty map (like delete) return a Set instead.
You can directly construct an NESet with the API from Data.Set.NonEmpty; it's more or less the same as constructing a normal Set, except you don't have access to empty. There are also a few ways to construct an NESet from a Set:
The nonEmptySet smart constructor will convert a
Set ainto aMaybe (NESet a), returning Nothing if the original Set was empty.You can use the insertSet family of functions to insert a value into a Set to create a guaranteed NESet.
You can use the IsNonEmpty and IsEmpty patterns to "pattern match" on a Set to reveal it as either containing a NESet or an empty map.
withNonEmpty offers a continuation-based interface for deconstructing a Set and treating it as if it were an NESet.
You can convert an NESet into a Set with toSet or IsNonEmpty, essentially "obscuring" the non-empty property from the type.
Instances17Foldable, Foldable1, Eq1, Ord1, Show1, IsList, …
Foldable NESetDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalFoldable1 NESetDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalTraverses elements in ascending order
Eq1 NESetDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalOrd1 NESetDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalShow1 NESetDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalOrd a => IsList (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalEq a => Eq (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.Internal(Data a, Ord a) => Data (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalOrd a => Ord (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.Internal(Read a, Ord a) => Read (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalShow a => Show (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalOrd a => Semigroup (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalLeft-biased union
NFData a => NFData (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.Internal(FromJSON a, Ord a) => FromJSON (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalToJSON a => ToJSON (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.InternalOrd a => IsNonEmptyList (NESet a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmpty.Listtype Item (NESet a) = aDefined in nonempty-containers-0.3.6.0 · Data.Set.NonEmpty.Internal