Data.Unfoldable.MaybeEmpty
- Package
- purescript-trivial-unfold
- Repository
- UnrelatedString/purescript-trivial-unfold
#MaybeEmpty Source
newtype MaybeEmpty :: forall k. (k -> Type) -> k -> Type
newtype MaybeEmpty f a
Lift an Unfoldable1
into an Unfoldable
by wrapping it in Maybe
,
such that an empty sequence gives Nothing
and a nonempty sequence gives
a nonempty Unfoldable1
in Just
.
Constructors
MaybeEmpty (Maybe (f a))
Instances
Newtype (MaybeEmpty f a) _
(Show (f a)) => Show (MaybeEmpty f a)
(Arbitrary (f a)) => Arbitrary (MaybeEmpty f a)
(Coarbitrary (f a)) => Coarbitrary (MaybeEmpty f a)
(Semigroup (f a)) => Semigroup (MaybeEmpty f a)
(Semigroup (f a)) => Monoid (MaybeEmpty f a)
(Bounded (f a)) => Bounded (MaybeEmpty f a)
(Semiring (f a)) => Semiring (MaybeEmpty f a)
Generic (MaybeEmpty f a) _
(Eq1 f) => Eq1 (MaybeEmpty f)
(Ord1 f) => Ord1 (MaybeEmpty f)
(Eq1 f, Eq a) => Eq (MaybeEmpty f a)
(Ord1 f, Ord a) => Ord (MaybeEmpty f a)
(Unfoldable1 f) => Unfoldable1 (MaybeEmpty f)
(Unfoldable1 f) => Unfoldable (MaybeEmpty f)
(Functor f) => Functor (MaybeEmpty f)
(Apply f) => Apply (MaybeEmpty f)
(Applicative f) => Applicative (MaybeEmpty f)
(Bind f, Traversable f) => Bind (MaybeEmpty f)
(Applicative f, Bind f, Traversable f) => Monad (MaybeEmpty f)
(Functor f) => Invariant (MaybeEmpty f)
(Alt f) => Alt (MaybeEmpty f)
(Alt f) => Plus (MaybeEmpty f)
empty = none
. Does not usePlus f
if it exists--and given that this is all about wrapping guaranteed non-empty containers, it probably doesn't.(Applicative f, Alt f) => Alternative (MaybeEmpty f)
(Extend f) => Extend (MaybeEmpty f)
(Foldable f) => Foldable (MaybeEmpty f)
(Traversable f) => Traversable (MaybeEmpty f)
#maybeEmpty Source
maybeEmpty :: forall f a b. b -> (f a -> b) -> MaybeEmpty f a -> b
Convenience wrapper for maybe
on the inner Maybe
. Can save an
import Data.Newtype (un)
if this is all you need from Data.Unfoldable.MaybeEmpty.
#maybeEmpty' Source
maybeEmpty' :: forall f a b. (Unit -> b) -> (f a -> b) -> MaybeEmpty f a -> b
#distributeMaybes Source
distributeMaybes :: forall f a. Unfoldable1 f => Functor f => MaybeEmpty f a -> f (Maybe a)
Creates 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)
Creates 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)
Unwraps and converts 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
Applies a function to the inner container if present.
Composes
Alt Maybe
withAlt f
. This does not seem likely to be particularly useful, but then again, what does?If you just want the first nonempty
MaybeEmpty f a
,unwrap
it toMaybe (f a)
.