Skip to content

Commit

Permalink
simplify cart shipping example
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Sep 1, 2023
1 parent b3d9db9 commit 9e0e551
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/Crem/Example/Cart/Shipping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
module Crem.Example.Cart.Shipping where

import Crem.BaseMachine
import Crem.Example.Cart.Application
import Crem.Example.Cart.Aggregate
import Crem.Example.Cart.Domain
import Crem.Example.Cart.Projection
import Crem.Render.RenderableVertices
Expand Down Expand Up @@ -48,18 +48,18 @@ shippingBasic = undefined
shipping :: StateMachine ShippingCommand [ShippingEvent]
shipping = Basic shippingBasic

writeModelWithShipping :: StateMachine (Either CartCommand ShippingCommand) [Either CartEvent ShippingEvent]
writeModelWithShipping = rmap (fmap Left ||| fmap Right) $ writeModel +++ shipping
aggregateWithShipping :: StateMachine (Either CartCommand ShippingCommand) [Either CartEvent ShippingEvent]
aggregateWithShipping = rmap (fmap Left ||| fmap Right) $ cart +++ shipping

paymentCompletePolicy :: StateMachine CartEvent [ShippingCommand]
paymentCompletePolicy = stateless $ \case
CartPaymentInitiated -> []
CartPaymentCompleted -> [StartShipping]

writeModelWithShipping' :: StateMachine (Either CartCommand ShippingCommand) [Either CartEvent ShippingEvent]
writeModelWithShipping' =
writeModelWithShipping :: StateMachine (Either CartCommand ShippingCommand) [Either CartEvent ShippingEvent]
writeModelWithShipping =
Feedback
writeModelWithShipping
aggregateWithShipping
(rmap (fmap Right) paymentCompletePolicy ||| stateless (const []))

data ShippingInfo
Expand All @@ -71,4 +71,4 @@ readModel :: StateMachine (Either CartEvent ShippingEvent) [Either CartView Ship
readModel = rmap (fmap Left ||| fmap Right) $ paymentStatus +++ shippingInfo

cartAndShipping :: StateMachine (Either CartCommand ShippingCommand) [Either CartView ShippingInfo]
cartAndShipping = Kleisli writeModelWithShipping' readModel
cartAndShipping = Kleisli writeModelWithShipping readModel

0 comments on commit 9e0e551

Please sign in to comment.