{-# OPTIONS_GHC -fno-warn-orphans #-}

module Pandora.Paradigm.Primary.Functor (module Exports, branches, match) where

import Pandora.Paradigm.Primary.Functor.Fix as Exports
import Pandora.Paradigm.Primary.Functor.Equivalence as Exports
import Pandora.Paradigm.Primary.Functor.Predicate as Exports
import Pandora.Paradigm.Primary.Functor.These as Exports
import Pandora.Paradigm.Primary.Functor.Validation as Exports
import Pandora.Paradigm.Primary.Functor.Wedge as Exports
import Pandora.Paradigm.Primary.Functor.Wye as Exports
import Pandora.Paradigm.Primary.Functor.Edges as Exports
import Pandora.Paradigm.Primary.Functor.Conclusion as Exports
import Pandora.Paradigm.Primary.Functor.Maybe as Exports
import Pandora.Paradigm.Primary.Functor.Endo as Exports
import Pandora.Paradigm.Primary.Functor.Proxy as Exports
import Pandora.Paradigm.Primary.Functor.Tagged as Exports
import Pandora.Paradigm.Primary.Functor.Product as Exports
import Pandora.Paradigm.Primary.Functor.Constant as Exports
import Pandora.Paradigm.Primary.Functor.Identity as Exports
import Pandora.Paradigm.Primary.Functor.Function as Exports

import Pandora.Pattern.Category (($))
import Pandora.Pattern.Functor.Adjoint (Adjoint ((-|), (|-)))
import Pandora.Paradigm.Primary.Object.Boolean ((?))

instance Adjoint (Product s) ((->) s) where
	(-|) :: a -> ((s :*: a) -> b) -> (s -> b)
	a
x -| :: a -> ((s :*: a) -> b) -> s -> b
-| (s :*: a) -> b
f = \s
s -> (s :*: a) -> b
f ((s :*: a) -> b) -> (s :*: a) -> b
forall (m :: * -> * -> *). Category m => m ~~> m
$ s
s s -> a -> s :*: a
forall s a. s -> a -> Product s a
:*: a
x
	(|-) :: (s :*: a) -> (a -> s -> b) -> b
	~(s
s :*: a
x) |- :: (s :*: a) -> (a -> s -> b) -> b
|- a -> s -> b
f = a -> s -> b
f a
x s
s

branches :: Maybe a -> Maybe a -> Wye a
branches :: Maybe a -> Maybe a -> Wye a
branches (Just a
x) (Just a
y) = a -> a -> Wye a
forall a. a -> a -> Wye a
Both a
x a
y
branches Maybe a
Nothing (Just a
y) = a -> Wye a
forall a. a -> Wye a
Right a
y
branches (Just a
x) Maybe a
Nothing = a -> Wye a
forall a. a -> Wye a
Left a
x
branches Maybe a
Nothing Maybe a
Nothing = Wye a
forall a. Wye a
End

match :: Predicate a -> (a -> r) -> a -> r -> r :*: a
match :: Predicate a -> (a -> r) -> a -> r -> r :*: a
match (Predicate a -> Boolean
p) a -> r
f a
x r
r = a -> Boolean
p a
x Boolean -> (r :*: a) -> (r :*: a) -> r :*: a
forall a. Boolean -> a -> a -> a
? a -> r
f a
x r -> a -> r :*: a
forall s a. s -> a -> Product s a
:*: a
x ((r :*: a) -> r :*: a) -> (r :*: a) -> r :*: a
forall (m :: * -> * -> *). Category m => m ~~> m
$ r
r r -> a -> r :*: a
forall s a. s -> a -> Product s a
:*: a
x