class Contravariant f => Decide f
The contravariant analogue of Alt.
If one thinks of f a as a consumer of as, then decide allows one
to handle the consumption of a value by choosing to handle it via
exactly one of two independent consumers. It redirects the input
completely into one of two consumers.
decide takes the "decision" method and the two potential consumers,
and returns the wrapped/combined consumer.
Mathematically, a functor being an instance of Decide means that it is
"semigroupoidal" with respect to the contravariant "either-based" Day
convolution (data EitherDay f g a = forall b c. EitherDay (f b) (g c) (a -> Either b c)).
That is, it is possible to define a function @(f `EitherDay` f) a ->
f a@ in a way that is associative.
decide :: (a -> Either b c) -> f b -> f c -> f a
Takes the "decision" method and the two potential consumers, and
returns the wrapped/combined consumer.
gdecide :: (Generic1 f, Decide (Rep1 f)) => (a -> Either b c) -> f b -> f c -> f a
Generic decide. Caveats:
Will not compile if f is a sum type.
Will not compile if f contains fields that do not mention its type variable.
-XDeriveGeneric is not smart enough to make instances where the type variable appears in negative position.
decided :: Decide f => f b -> f c -> f (Either b c)
For decided x y, the resulting f (Either b c) will direct
Lefts to be consumed by x, and Rights to be consumed by y.
gdecided :: (Generic1 f, Decide (Rep1 f)) => f b -> f c -> f (Either b c)
Generic decided. Caveats are the same as for gdecide.
Instances
26
instance Decidable f => Decide (WrappedDivisible f)This instance is only available if the +contravariant cabal flag is
enabled.
instance Decide Comparisoninstance Decide Equivalenceinstance Decide Predicateinstance Decide (Op r)Unlike Decidable, requires no constraint on r.
instance Decide f => Decide (Alt f)instance Decide U1instance Decide V1Has no Decidable or Conclude instance.
instance Decide f => Decide (Rec1 f)instance Decide f => Decide (M1 i c f)instance (Decide f, Decide g) => Decide (f :*: g)instance (Apply f, Decide g) => Decide (f :.: g)Unlike Decidable, requires only Apply on f.
instance Decide f => Decide (Backwards f)instance Decide f => Decide (IdentityT f)instance Decide m => Decide (ReaderT r m)instance Decide m => Decide (Lazy.RWST r w s m)instance Decide m => Decide (Strict.RWST r w s m)instance Divise m => Decide (MaybeT m)instance Decide m => Decide (Lazy.StateT s m)instance Decide m => Decide (Strict.StateT s m)instance Decide m => Decide (Lazy.WriterT w m)instance Decide m => Decide (Strict.WriterT w m)instance (Apply f, Decide g) => Decide (Compose f g)Unlike Decidable, requires only Apply on f.
instance (Decide f, Decide g) => Decide (Product f g)instance Decide f => Decide (Reverse f)instance Decide Proxy
- Maintainer
- Edward Kmett <ekmett@gmail.com>
- Portability
- portable
- Copyright
- (C) 2021 Edward Kmett
- License
- BSD-style (see the file LICENSE)