Module

Data.Unfoldable.MaybeEmpty

Package
purescript-trivial-unfold
Repository
UnrelatedString/purescript-trivial-unfold

#MaybeEmpty Source

newtype MaybeEmpty :: forall k. (k -> Type) -> k -> Typenewtype MaybeEmpty f a

Lifts a nonempty container into a possibly-empty container by wrapping it in Maybe. such that an empty sequence corresponds to Nothing and a nonempty sequence corresponds to the nonempty container in a Just.

Constructors

Instances

#maybeEmpty Source

maybeEmpty :: forall f a b. b -> (f a -> b) -> MaybeEmpty f a -> b

Convenience wrapper for maybe on the inner Maybe, to save you an un or toAlternative.

#maybeEmpty' Source

maybeEmpty' :: forall f a b. (Unit -> b) -> (f a -> b) -> MaybeEmpty f a -> b

#justNonempty Source

justNonempty :: forall f a. f a -> MaybeEmpty f a

Wrap an existing container into a MaybeEmpty.

#distributeMaybes Source

distributeMaybes :: forall f a. Unfoldable1 f => Functor f => MaybeEmpty f a -> f (Maybe a)

Create an f containing a single Nothing if empty.

Although Data.Unfoldable calls them "unfoldable functors", Functor isn't actually a superclass of Unfoldable1. On the off chance that you for some reason do in fact have an Unfoldable1 type which is not a Functor but also want to use this, consider emptyIfNone from Data.Unfoldable.Trivial instead.

#distributeMaybesA Source

distributeMaybesA :: forall f a. Applicative f => MaybeEmpty f a -> f (Maybe a)

Create an f containing Nothing if empty, using pure instead of singleton.

#toAlternative Source

toAlternative :: forall u f a. Alternative f => MaybeEmpty u a -> f (u a)

Unwrap and convert the inner Maybe into an alternative Alternative. (ba dum tss)

#maybeOver Source

maybeOver :: forall f g a b. (f a -> g b) -> MaybeEmpty f a -> MaybeEmpty g b

Apply a function to the inner container if present.