module Pandora.Paradigm.Primary.Functor.These where

import Pandora.Pattern.Category (($))
import Pandora.Pattern.Functor.Covariant (Covariant ((<$>)))
import Pandora.Pattern.Functor.Pointable (Pointable (point))
import Pandora.Pattern.Functor.Traversable (Traversable ((->>)))

data These e a = This a | That e | These e a

instance Covariant (These e) where
	a -> b
f <$> :: (a -> b) -> These e a -> These e b
<$> This a
x = b -> These e b
forall e a. a -> These e a
This (b -> These e b) -> b -> These e b
forall (m :: * -> * -> *) a b. Category m => m a b -> m a b
$ a -> b
f a
x
	a -> b
_ <$> That e
y = e -> These e b
forall e a. e -> These e a
That e
y
	a -> b
f <$> These e
y a
x = e -> b -> These e b
forall e a. e -> a -> These e a
These e
y (b -> These e b) -> b -> These e b
forall (m :: * -> * -> *) a b. Category m => m a b -> m a b
$ a -> b
f a
x

instance Pointable (These e) where
	point :: a |-> These e
point = a |-> These e
forall e a. a -> These e a
This

instance Traversable (These e) where
	This a
x ->> :: These e a -> (a -> u b) -> (u :. These e) := b
->> a -> u b
f = b -> These e b
forall e a. a -> These e a
This (b -> These e b) -> u b -> (u :. These e) := b
forall (t :: * -> *) a b. Covariant t => (a -> b) -> t a -> t b
<$> a -> u b
f a
x
	That e
y ->> a -> u b
_ = These e b |-> u
forall (t :: * -> *) a. Pointable t => a |-> t
point (These e b |-> u) -> These e b |-> u
forall (m :: * -> * -> *) a b. Category m => m a b -> m a b
$ e -> These e b
forall e a. e -> These e a
That e
y
	These e
y a
x ->> a -> u b
f = e -> b -> These e b
forall e a. e -> a -> These e a
These e
y (b -> These e b) -> u b -> (u :. These e) := b
forall (t :: * -> *) a b. Covariant t => (a -> b) -> t a -> t b
<$> a -> u b
f a
x

these :: (a -> r) -> (e -> r) -> (e -> a -> r) -> These e a -> r
these :: (a -> r) -> (e -> r) -> (e -> a -> r) -> These e a -> r
these a -> r
f e -> r
_ e -> a -> r
_ (This a
x) = a -> r
f a
x
these a -> r
_ e -> r
g e -> a -> r
_ (That e
y) = e -> r
g e
y
these a -> r
_ e -> r
_ e -> a -> r
h (These e
y a
x) = e -> a -> r
h e
y a
x