If s is an instance of HasNonEmpty, it means that there is
a corresponding "non-empty" version of s, NE s.
In order for things to be well-behaved, we expect that nonEmpty and
maybe empty fromNonEmpty should form an isomorphism (or that
withNonEmpty empty fromNonEmpty == id. In addition,
the following properties should hold for most exectations:
(x == empty) ==> isEmpty x(x == empty) ==> isNothing (nonEmpty x)isEmpty x ==> isNothing (nonEmpty x)unsafeToNonEmpty x == fromJust (nonEmpty x)Usually,
not (isEmpty x) ==> isJust (nonEmpty x), but this isn't necessary.
Methods
nonEmpty :: s -> Maybe (NE s)fromNonEmpty :: NE s -> sConvert a
NE s(non-emptys) back into ans, "obscuring" its non-emptiness from its type.withNonEmpty :: r -> (NE s -> r) -> s -> rContinuation-based version of nonEmpty, which can be more efficient in certain situations.
withNonEmpty empty fromNonEmptyshould beid.empty :: sAn empty
s.isEmpty :: s -> BoolCheck if an
sis empty.unsafeToNonEmpty :: s -> NE sUnsafely coerce an
sinto anNE s(non-emptys). Is undefined (throws a runtime exception when evaluation is attempted) when thesis empty.
Instances7HasNonEmpty, …
HasNonEmpty IntSetDefined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty (IntMap a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty (Seq a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty (Set a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty (Vector a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty [a]Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmptyHasNonEmpty (Map k a)Defined in nonempty-containers-0.3.6.0 · Data.Containers.NonEmpty