module SupplyChain.Vendor
(
Vendor (Vendor, handle),
(>->), id,
function, action, state, map, absurd,
run, eval, eval',
alter, alter',
)
where
import SupplyChain.Core.Effect (Effect)
import SupplyChain.Core.Job (Job, effect)
import SupplyChain.Core.Referral (Referral (..))
import SupplyChain.Core.Vendor (Vendor (..))
import SupplyChain.JobAndVendor (loop')
import qualified SupplyChain.Core.Connect as Connect
import qualified SupplyChain.Core.Job as Job
import qualified SupplyChain.Core.Referral as Referral
import qualified SupplyChain.Core.Vendor as Vendor
import Control.Applicative (pure)
import Control.Monad (Monad)
import Data.Function ((.))
import Data.Functor ((<&>))
import Data.Functor.Const (Const)
import Data.Void (Void)
(>->) :: Vendor up middle action
-> Vendor middle down action
-> Vendor up down action
>-> :: forall (up :: * -> *) (middle :: * -> *) (action :: * -> *)
(down :: * -> *).
Vendor up middle action
-> Vendor middle down action -> Vendor up down action
(>->) = forall (up :: * -> *) (middle :: * -> *) (action :: * -> *)
(down :: * -> *).
Vendor up middle action
-> Vendor middle down action -> Vendor up down action
(Connect.>->)
run :: Monad action => Vendor (Const Void) down action
-> down product
-> action (Referral (Const Void) down action product)
run :: forall (action :: * -> *) (down :: * -> *) product.
Monad action =>
Vendor (Const Void) down action
-> down product
-> action (Referral (Const Void) down action product)
run = forall (action :: * -> *) (down :: * -> *) product.
Monad action =>
Vendor (Const Void) down action
-> down product
-> action (Referral (Const Void) down action product)
Vendor.run
eval :: Vendor (Const Void) down (Const Void)
-> down product
-> Referral (Const Void) down (Const Void) product
eval :: forall (down :: * -> *) product.
Vendor (Const Void) down (Const Void)
-> down product -> Referral (Const Void) down (Const Void) product
eval = forall (down :: * -> *) product.
Vendor (Const Void) down (Const Void)
-> down product -> Referral (Const Void) down (Const Void) product
Vendor.eval
eval' :: Vendor (Const Void) down (Const Void)
-> down product
-> product
eval' :: forall (down :: * -> *) product.
Vendor (Const Void) down (Const Void) -> down product -> product
eval' Vendor (Const Void) down (Const Void)
v down product
r = forall (up :: * -> *) (down :: * -> *) (action :: * -> *) product.
Referral up down action product -> product
Referral.product (forall (down :: * -> *) product.
Vendor (Const Void) down (Const Void)
-> down product -> Referral (Const Void) down (Const Void) product
Vendor.eval Vendor (Const Void) down (Const Void)
v down product
r)
absurd :: Vendor up (Const Void) action
absurd :: forall (up :: * -> *) (action :: * -> *).
Vendor up (Const Void) action
absurd = forall (up :: * -> *) (down :: * -> *) (action :: * -> *).
(forall product.
down product -> Job up action (Referral up down action product))
-> Vendor up down action
Vendor (\case{})
id :: Vendor i i action
id :: forall (i :: * -> *) (action :: * -> *). Vendor i i action
id = forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall x. down x -> Job up action x) -> Vendor up down action
loop' forall (up :: * -> *) product (action :: * -> *).
up product -> Job up action product
Job.order
function :: (forall response. down response -> response)
-> Vendor up down action
function :: forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall response. down response -> response)
-> Vendor up down action
function forall response. down response -> response
f = forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall x. down x -> Job up action x) -> Vendor up down action
loop' (forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall response. down response -> response
f)
action :: (forall response. down response -> action response)
-> Vendor up down action
action :: forall (down :: * -> *) (action :: * -> *) (up :: * -> *).
(forall response. down response -> action response)
-> Vendor up down action
action forall response. down response -> action response
f = forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall x. down x -> Job up action x) -> Vendor up down action
loop' (forall (action :: * -> *) product (up :: * -> *).
action product -> Job up action product
Job.perform forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall response. down response -> action response
f)
state ::
s
-> (forall response. down response -> s -> Job up action (response, s))
-> Vendor up down action
state :: forall s (down :: * -> *) (up :: * -> *) (action :: * -> *).
s
-> (forall response.
down response -> s -> Job up action (response, s))
-> Vendor up down action
state s
initial forall response. down response -> s -> Job up action (response, s)
step = s -> Vendor up down action
go s
initial
where
go :: s -> Vendor up down action
go s
s =
Vendor{ handle :: forall product.
down product -> Job up action (Referral up down action product)
handle = \down product
request ->
forall response. down response -> s -> Job up action (response, s)
step down product
request s
s forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \(product
response, s
s') ->
forall (up :: * -> *) (down :: * -> *) (action :: * -> *) product.
product -> Vendor up down action -> Referral up down action product
Referral product
response (s -> Vendor up down action
go s
s') }
map :: (forall response. down response -> up response) -> Vendor up down action
map :: forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall response. down response -> up response)
-> Vendor up down action
map forall response. down response -> up response
f = forall (down :: * -> *) (up :: * -> *) (action :: * -> *).
(forall x. down x -> Job up action x) -> Vendor up down action
loop' (forall (up :: * -> *) product (action :: * -> *).
up product -> Job up action product
Job.order forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall response. down response -> up response
f)
alter :: (forall x. Effect up action x -> Job up' action' x)
-> Vendor up down action -> Vendor up' down action'
alter :: forall (up :: * -> *) (action :: * -> *) (up' :: * -> *)
(action' :: * -> *) (down :: * -> *).
(forall x. Effect up action x -> Job up' action' x)
-> Vendor up down action -> Vendor up' down action'
alter = forall (up :: * -> *) (action :: * -> *) (up' :: * -> *)
(action' :: * -> *) (down :: * -> *).
(forall x. Effect up action x -> Job up' action' x)
-> Vendor up down action -> Vendor up' down action'
Vendor.alter
alter' :: (forall x. Effect up action x -> Effect up' action' x)
-> Vendor up down action -> Vendor up' down action'
alter' :: forall (up :: * -> *) (action :: * -> *) (up' :: * -> *)
(action' :: * -> *) (down :: * -> *).
(forall x. Effect up action x -> Effect up' action' x)
-> Vendor up down action -> Vendor up' down action'
alter' forall x. Effect up action x -> Effect up' action' x
f = forall (up :: * -> *) (action :: * -> *) (up' :: * -> *)
(action' :: * -> *) (down :: * -> *).
(forall x. Effect up action x -> Job up' action' x)
-> Vendor up down action -> Vendor up' down action'
Vendor.alter (forall (up :: * -> *) (action :: * -> *) product.
Effect up action product -> Job up action product
effect forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall x. Effect up action x -> Effect up' action' x
f)