functor-combinators-0.4.1.2: Tools for functor combinator-based program design
Copyright(c) Justin Le 2021
LicenseBSD3
Maintainerjustin@jle.im
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Functor.Invariant.Internative

Description

Contains the classes Inalt and Inplus, the invariant counterparts to AltPlus and DecideConclude and Alternative/Decidable.

Since: 0.4.0.0

Synopsis

Typeclass

class Invariant f => Inalt f where Source #

The invariant counterpart of Alt and Decide.

Conceptually you can think of Alt as, given a way to "inject" a and b as c, lets you merge f a (producer of a) and f b (producer of b) into a f c (producer of c), in an "either-or" fashion. Decide can be thought of as, given a way to "discriminate" a c as either a a or a b, lets you merge f a (consumer of a) and f b (consumder of b) into a f c (consumer of c) in an "either-or" forking fashion (split the c into a or b, and use the appropriate handler).

Inalt, for swerve, requires both an injecting function and a choosing function in order to merge f b (producer and consumer of b) and f c (producer and consumer of c) into a f a in an either-or manner. You can think of it as, for the f a, it "chooses" if the a is actually a b or a c with the a -> Either b c, feeds it to either the original f b or the original f c, and then re-injects the output back into a a with the b -> a or the c -> a.

Since: 0.4.0.0

Minimal complete definition

swerve | swerved

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> f b -> f c -> f a Source #

Like <!>, decide, or choose, but requires both an injecting and a choosing function.

It is used to merge f b (producer and consumer of b) and f c (producer and consumer of c) into a f a in an either-or manner. You can think of it as, for the f a, it "chooses" if the a is actually a b or a c with the a -> Either b c, feeds it to either the original f b or the original f c, and then re-injects the output back into a a with the b -> a or the c -> a.

An important property is that it will only ever use exactly one of the options given in order to fulfil its job. If you swerve an f a and an f b into an f c, in order to consume/produdce the c, it will only use either the f a or the f b -- exactly one of them.

Since: 0.4.0.0

swerved :: f a -> f b -> f (Either a b) Source #

A simplified version of swerive that splits to and from an Either. You can then use invmap to reshape it into the proper shape.

Since: 0.4.0.0

Instances

Instances details
Inalt SettableStateVar Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> SettableStateVar b -> SettableStateVar c -> SettableStateVar a Source #

swerved :: SettableStateVar a -> SettableStateVar b -> SettableStateVar (Either a b) Source #

Inalt Comparison Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Comparison b -> Comparison c -> Comparison a Source #

swerved :: Comparison a -> Comparison b -> Comparison (Either a b) Source #

Inalt Equivalence Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Equivalence b -> Equivalence c -> Equivalence a Source #

swerved :: Equivalence a -> Equivalence b -> Equivalence (Either a b) Source #

Inalt Predicate Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Predicate b -> Predicate c -> Predicate a Source #

swerved :: Predicate a -> Predicate b -> Predicate (Either a b) Source #

Inalt First Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> First b -> First c -> First a Source #

swerved :: First a -> First b -> First (Either a b) Source #

Inalt Last Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Last b -> Last c -> Last a Source #

swerved :: Last a -> Last b -> Last (Either a b) Source #

Inalt First Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> First b -> First c -> First a Source #

swerved :: First a -> First b -> First (Either a b) Source #

Inalt Last Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Last b -> Last c -> Last a Source #

swerved :: Last a -> Last b -> Last (Either a b) Source #

Inalt IntMap Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> IntMap b -> IntMap c -> IntMap a Source #

swerved :: IntMap a -> IntMap b -> IntMap (Either a b) Source #

Inalt Seq Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Seq b -> Seq c -> Seq a Source #

swerved :: Seq a -> Seq b -> Seq (Either a b) Source #

Inalt IO Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> IO b -> IO c -> IO a Source #

swerved :: IO a -> IO b -> IO (Either a b) Source #

Inalt NEIntMap Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> NEIntMap b -> NEIntMap c -> NEIntMap a Source #

swerved :: NEIntMap a -> NEIntMap b -> NEIntMap (Either a b) Source #

Inalt NESeq Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> NESeq b -> NESeq c -> NESeq a Source #

swerved :: NESeq a -> NESeq b -> NESeq (Either a b) Source #

Inalt NonEmpty Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> NonEmpty b -> NonEmpty c -> NonEmpty a Source #

swerved :: NonEmpty a -> NonEmpty b -> NonEmpty (Either a b) Source #

Inalt Maybe Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Maybe b -> Maybe c -> Maybe a Source #

swerved :: Maybe a -> Maybe b -> Maybe (Either a b) Source #

Inalt [] Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> [b] -> [c] -> [a] Source #

swerved :: [a] -> [b] -> [Either a b] Source #

FreeOf Inalt DecAlt1 Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Associated Types

type FreeFunctorBy DecAlt1 :: (Type -> Type) -> Constraint Source #

Methods

fromFree :: forall (f :: Type -> Type). DecAlt1 f ~> Final Inalt f Source #

toFree :: forall (f :: Type -> Type). FreeFunctorBy DecAlt1 f => Final Inalt f ~> DecAlt1 f Source #

MonadPlus m => Inalt (WrappedMonad m) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> WrappedMonad m b -> WrappedMonad m c -> WrappedMonad m a Source #

swerved :: WrappedMonad m a -> WrappedMonad m b -> WrappedMonad m (Either a b) Source #

Inalt (Either e) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Either e b -> Either e c -> Either e a Source #

swerved :: Either e a -> Either e b -> Either e (Either a b) Source #

Inalt (Op r) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Op r b -> Op r c -> Op r a Source #

swerved :: Op r a -> Op r b -> Op r (Either a b) Source #

Inalt (Proxy :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Proxy b -> Proxy c -> Proxy a Source #

swerved :: Proxy a -> Proxy b -> Proxy (Either a b) Source #

Inalt (U1 :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> U1 b -> U1 c -> U1 a Source #

swerved :: U1 a -> U1 b -> U1 (Either a b) Source #

Inalt (V1 :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> V1 b -> V1 c -> V1 a Source #

swerved :: V1 a -> V1 b -> V1 (Either a b) Source #

Ord k => Inalt (Map k) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Map k b -> Map k c -> Map k a Source #

swerved :: Map k a -> Map k b -> Map k (Either a b) Source #

Inalt (Dec f) Source # 
Instance details

Defined in Data.Functor.Contravariant.Divisible.Free

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Dec f b -> Dec f c -> Dec f a Source #

swerved :: Dec f a -> Dec f b -> Dec f (Either a b) Source #

Inalt (Dec1 f) Source # 
Instance details

Defined in Data.Functor.Contravariant.Divisible.Free

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Dec1 f b -> Dec1 f c -> Dec1 f a Source #

swerved :: Dec1 f a -> Dec1 f b -> Dec1 f (Either a b) Source #

Inalt (DecAlt f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative.Free

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> DecAlt f b -> DecAlt f c -> DecAlt f a Source #

swerved :: DecAlt f a -> DecAlt f b -> DecAlt f (Either a b) Source #

Invariant f => Inalt (DecAlt1 f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative.Free

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> DecAlt1 f b -> DecAlt1 f c -> DecAlt1 f a Source #

swerved :: DecAlt1 f a -> DecAlt1 f b -> DecAlt1 f (Either a b) Source #

Ord k => Inalt (NEMap k) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> NEMap k b -> NEMap k c -> NEMap k a Source #

swerved :: NEMap k a -> NEMap k b -> NEMap k (Either a b) Source #

Hashable k => Inalt (HashMap k) Source #

Does not require Eq k since base-4.16

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> HashMap k b -> HashMap k c -> HashMap k a Source #

swerved :: HashMap k a -> HashMap k b -> HashMap k (Either a b) Source #

ArrowPlus a => Inalt (WrappedArrow a b) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b0 -> a0) -> (c -> a0) -> (a0 -> Either b0 c) -> WrappedArrow a b b0 -> WrappedArrow a b c -> WrappedArrow a b a0 Source #

swerved :: WrappedArrow a b a0 -> WrappedArrow a b b0 -> WrappedArrow a b (Either a0 b0) Source #

Inalt f => Inalt (Rec1 f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Rec1 f b -> Rec1 f c -> Rec1 f a Source #

swerved :: Rec1 f a -> Rec1 f b -> Rec1 f (Either a b) Source #

Decide f => Inalt (WrappedDivisible f) Source #

Ignores the covariant part of gather

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> WrappedDivisible f b -> WrappedDivisible f c -> WrappedDivisible f a Source #

swerved :: WrappedDivisible f a -> WrappedDivisible f b -> WrappedDivisible f (Either a b) Source #

(Decidable f, Invariant f) => Inalt (WrappedDivisibleOnly f) Source #

Ignores the covariant part of gather

Instance details

Defined in Data.Functor.Invariant.Internative

Decide f => Inalt (WrappedContravariant f) Source #

Ignores the covariant part of gather

Instance details

Defined in Data.Functor.Invariant.Internative

Alt f => Inalt (WrappedFunctor f) Source #

Ignores the contravariant part of swerve

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> WrappedFunctor f b -> WrappedFunctor f c -> WrappedFunctor f a Source #

swerved :: WrappedFunctor f a -> WrappedFunctor f b -> WrappedFunctor f (Either a b) Source #

Inalt f => Inalt (Backwards f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Backwards f b -> Backwards f c -> Backwards f a Source #

swerved :: Backwards f a -> Backwards f b -> Backwards f (Either a b) Source #

Inalt f => Inalt (IdentityT f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> IdentityT f b -> IdentityT f c -> IdentityT f a Source #

swerved :: IdentityT f a -> IdentityT f b -> IdentityT f (Either a b) Source #

Inalt f => Inalt (Reverse f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Reverse f b -> Reverse f c -> Reverse f a Source #

swerved :: Reverse f a -> Reverse f b -> Reverse f (Either a b) Source #

(Inalt f, Inalt g) => Inalt (Product f g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Product f g b -> Product f g c -> Product f g a Source #

swerved :: Product f g a -> Product f g b -> Product f g (Either a b) Source #

(Inalt f, Inalt g) => Inalt (f :*: g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> (f :*: g) b -> (f :*: g) c -> (f :*: g) a Source #

swerved :: (f :*: g) a -> (f :*: g) b -> (f :*: g) (Either a b) Source #

Invariant f => Inalt (Chain1 Night f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Chain1 Night f b -> Chain1 Night f c -> Chain1 Night f a Source #

swerved :: Chain1 Night f a -> Chain1 Night f b -> Chain1 Night f (Either a b) Source #

Inalt (Final Inalt f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Final Inalt f b -> Final Inalt f c -> Final Inalt f a Source #

swerved :: Final Inalt f a -> Final Inalt f b -> Final Inalt f (Either a b) Source #

Inalt (Final Inplus f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Final Inplus f b -> Final Inplus f c -> Final Inplus f a Source #

swerved :: Final Inplus f a -> Final Inplus f b -> Final Inplus f (Either a b) Source #

Inalt (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Final Internative f b -> Final Internative f c -> Final Internative f a Source #

swerved :: Final Internative f a -> Final Internative f b -> Final Internative f (Either a b) Source #

Invariant (Final Inalt f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

invmap :: (a -> b) -> (b -> a) -> Final Inalt f a -> Final Inalt f b #

Inalt f => Inalt (M1 i t f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> M1 i t f b -> M1 i t f c -> M1 i t f a Source #

swerved :: M1 i t f a -> M1 i t f b -> M1 i t f (Either a b) Source #

Inalt (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Chain Night Not f b -> Chain Night Not f c -> Chain Night Not f a Source #

swerved :: Chain Night Not f a -> Chain Night Not f b -> Chain Night Not f (Either a b) Source #

class Inalt f => Inplus f where Source #

The invariant counterpart of Alt and Conclude.

The main important action is described in Inalt, but this adds reject, which is the counterpart to empty and conclude and conquer. It's the identity to swerve; if combine two f as with swerve, and one of them is reject, then that banch will never be taken.

Conceptually, if you think of swerve as "choosing one path and re-injecting back", then reject introduces a branch that is impossible to take.

Methods

reject :: (a -> Void) -> f a Source #

Instances

Instances details
Inplus SettableStateVar Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> SettableStateVar a Source #

Inplus Comparison Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Comparison a Source #

Inplus Equivalence Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Equivalence a Source #

Inplus Predicate Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Predicate a Source #

Inplus First Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> First a Source #

Inplus Last Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Last a Source #

Inplus Seq Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Seq a Source #

Inplus IO Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> IO a Source #

Inplus Maybe Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Maybe a Source #

Inplus [] Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> [a] Source #

FreeOf Inplus DecAlt Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Associated Types

type FreeFunctorBy DecAlt :: (Type -> Type) -> Constraint Source #

Methods

fromFree :: forall (f :: Type -> Type). DecAlt f ~> Final Inplus f Source #

toFree :: forall (f :: Type -> Type). FreeFunctorBy DecAlt f => Final Inplus f ~> DecAlt f Source #

MonadPlus m => Inplus (WrappedMonad m) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> WrappedMonad m a Source #

Inplus (Op r) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Op r a Source #

Inplus (Proxy :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Proxy a Source #

Inplus (U1 :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> U1 a Source #

Inplus (Dec f) Source # 
Instance details

Defined in Data.Functor.Contravariant.Divisible.Free

Methods

reject :: (a -> Void) -> Dec f a Source #

Inplus (DecAlt f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative.Free

Methods

reject :: (a -> Void) -> DecAlt f a Source #

ArrowPlus a => Inplus (WrappedArrow a b) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a0 -> Void) -> WrappedArrow a b a0 Source #

Inplus f => Inplus (Rec1 f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Rec1 f a Source #

Conclude f => Inplus (WrappedDivisible f) Source #
reject = conclude
Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> WrappedDivisible f a Source #

(Decidable f, Invariant f) => Inplus (WrappedDivisibleOnly f) Source #
reject = lose
Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> WrappedDivisibleOnly f a Source #

Conclude f => Inplus (WrappedContravariant f) Source #
reject = conclude
Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> WrappedContravariant f a Source #

Plus f => Inplus (WrappedFunctor f) Source #
reject _ = zero
Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> WrappedFunctor f a Source #

Inplus f => Inplus (Backwards f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Backwards f a Source #

Inplus f => Inplus (IdentityT f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> IdentityT f a Source #

Inplus f => Inplus (Reverse f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Reverse f a Source #

Inalt (Final Inplus f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Final Inplus f b -> Final Inplus f c -> Final Inplus f a Source #

swerved :: Final Inplus f a -> Final Inplus f b -> Final Inplus f (Either a b) Source #

(Inplus f, Inplus g) => Inplus (Product f g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> Product f g a Source #

(Inplus f, Inplus g) => Inplus (f :*: g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> (f :*: g) a Source #

Inplus (Final Inplus f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

reject :: (a -> Void) -> Final Inplus f a Source #

Inplus (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

reject :: (a -> Void) -> Final Internative f a Source #

Invariant (Final Inplus f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

invmap :: (a -> b) -> (b -> a) -> Final Inplus f a -> Final Inplus f b #

Inplus f => Inplus (M1 i t f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Methods

reject :: (a -> Void) -> M1 i t f a Source #

Inplus (Chain Night Not f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Chain

Methods

reject :: (a -> Void) -> Chain Night Not f a Source #

class (Inplus f, Inplicative f) => Internative f Source #

The invariant counterpart to Alternative and Decidable: represents a combination of both Applicative and Alt, or Divisible and Conclude. There are laws?

Instances

Instances details
Internative SettableStateVar Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Comparison Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Equivalence Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Predicate Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative First Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Last Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Seq Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative IO Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative Maybe Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative [] Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

MonadPlus m => Internative (WrappedMonad m) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Monoid r => Internative (Op r) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative (Proxy :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative (U1 :: Type -> Type) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

ArrowPlus a => Internative (WrappedArrow a b) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative f => Internative (Rec1 f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

(Conclude f, Divisible f, Divise f) => Internative (WrappedDivisible f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative

(Decidable f, Invariant f) => Internative (WrappedDivisibleOnly f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative

(Conclude f, Divisible f, Divise f) => Internative (WrappedContravariant f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative

(Alternative f, Plus f, Apply f) => Internative (WrappedFunctor f) Source # 
Instance details

Defined in Data.Functor.Invariant.Internative

Internative f => Internative (Backwards f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative f => Internative (IdentityT f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Internative f => Internative (Reverse f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Inplicative (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

knot :: a -> Final Internative f a Source #

Inply (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

gather :: (b -> c -> a) -> (a -> (b, c)) -> Final Internative f b -> Final Internative f c -> Final Internative f a Source #

gathered :: Final Internative f a -> Final Internative f b -> Final Internative f (a, b) Source #

Inalt (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

swerve :: (b -> a) -> (c -> a) -> (a -> Either b c) -> Final Internative f b -> Final Internative f c -> Final Internative f a Source #

swerved :: Final Internative f a -> Final Internative f b -> Final Internative f (Either a b) Source #

Inplus (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

reject :: (a -> Void) -> Final Internative f a Source #

(Internative f, Internative g) => Internative (Product f g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

(Internative f, Internative g) => Internative (f :*: g) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Invariant (Final Internative f) Source #

Since: 0.4.0.0

Instance details

Defined in Data.HFunctor.Final

Methods

invmap :: (a -> b) -> (b -> a) -> Final Internative f a -> Final Internative f b #

Internative f => Internative (M1 i t f) Source #

Since: 0.4.1.0

Instance details

Defined in Data.Functor.Invariant.Internative

Assembling Helpers

swervedN :: Inplus f => NP f as -> f (NS I as) Source #

Convenient wrapper to build up an Inplus instance on by providing each branch of it. This makes it much easier to build up longer chains because you would only need to write the splitting/joining functions in one place.

For example, if you had a data type

data MyType = MTI Int | MTB Bool | MTS String

and an invariant functor and Inplus instance Prim (representing, say, a bidirectional parser, where Prim Int is a bidirectional parser for an Int), then you could assemble a bidirectional parser for a MyType@ using:

invmap (case MTI x -> Z (I x); MTB y -> S (Z (I y)); MTS z -> S (S (Z (I z))))
       (case Z (I x) -> MTI x; S (Z (I y)) -> MTB y; S (S (Z (I z))) -> MTS z) $
  swervedN $ intPrim
              :* boolPrim
              :* stringPrim
              :* Nil

Some notes on usefulness depending on how many components you have:

  • If you have 0 components, use reject directly.
  • If you have 1 component, use inject directly.
  • If you have 2 components, use swerve directly.
  • If you have 3 or more components, these combinators may be useful; otherwise you'd need to manually peel off eithers one-by-one.

Since: 0.4.1.0

swervedNMap :: Inplus f => (NS I as -> b) -> (b -> NS I as) -> NP f as -> f b Source #

Given a function to "discern out" a data type into possible NS (multi-way Either) branches and one to re-assemble each brann, swerve all of the components together.

For example, if you had a data type

data MyType = MTI Int | MTB Bool | MTS String

and an invariant functor and Inplus instance Prim (representing, say, a bidirectional parser, where Prim Int is a bidirectional parser for an Int), then you could assemble a bidirectional parser for a MyType@ using:

swervedNMap
     (case MTI x -> Z (I x); MTB y -> S (Z (I y)); MTS z -> S (S (Z (I z))))
     (case Z (I x) -> MTI x; S (Z (I y)) -> MTB y; S (S (Z (I z))) -> MTS z) $
     $ intPrim
    :* boolPrim
    :* stringPrim
    :* Nil

Some notes on usefulness depending on how many components you have:

  • If you have 0 components, use reject directly.
  • If you have 1 component, you don't need anything.
  • If you have 2 components, use swerve directly.
  • If you have 3 or more components, these combinators may be useful; otherwise you'd need to manually peel off eithers one-by-one.

See notes on swervedNMap for more details and caveats.

Since: 0.4.1.0

swervedN1 :: Inalt f => NP f (a ': as) -> f (NS I (a ': as)) Source #

A version of swervedN for non-empty NP, but only requiring an Inalt instance.

Since: 0.4.1.0

swervedN1Map :: Inalt f => (NS I (a ': as) -> b) -> (b -> NS I (a ': as)) -> NP f (a ': as) -> f b Source #

A version of swervedNMap for non-empty NS, but only requiring an Inalt instance.

Since: 0.4.1.0