-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApplication.hs
32 lines (24 loc) · 1.08 KB
/
Application.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Crem.Example.RiskManager.Application where
import Crem.Example.RiskManager.Aggregate (riskAggregate)
import Crem.Example.RiskManager.Domain (RiskCommand, RiskEvent)
import Crem.Example.RiskManager.Policy (riskPolicy)
import Crem.Example.RiskManager.Projection (ReceivedData, riskProjection)
import Crem.StateMachine
import "base" Data.List (singleton)
import "base" Data.Maybe (maybeToList)
import "profunctors" Data.Profunctor (rmap)
import Prelude hiding ((.))
aggregate :: StateMachine RiskCommand [RiskEvent]
aggregate = rmap maybeToList $ Basic riskAggregate
policy :: StateMachine RiskEvent [RiskCommand]
policy = rmap maybeToList riskPolicy
writeModel :: StateMachine RiskCommand [RiskEvent]
writeModel = Feedback aggregate policy
projection :: StateMachine RiskEvent ReceivedData
projection = Basic riskProjection
readModel :: StateMachine RiskEvent [ReceivedData]
readModel = rmap singleton projection
whole :: StateMachine RiskCommand [ReceivedData]
whole = Kleisli writeModel readModel
riskApplication :: StateMachine RiskCommand ReceivedData
riskApplication = rmap mconcat whole