Last active
July 22, 2020 04:48
-
-
Save bfollington/87e8ba5b647bbc048277dd34407883c0 to your computer and use it in GitHub Desktop.
Imagining a workflow DSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sketch | |
type Step = | |
| VSI | |
| BusinessAddress | |
| Offer | |
| AccountHolder | |
| BusinessDetails | |
| Identity | |
| Concessions | |
| Consent | |
| Feedback | |
| Thanks | |
type Predicate<'state> = 'state -> bool | |
type ConditionalStep<'state> = Predicate<'state> * Step | |
type WorkflowStep<'state> = | |
| Step of Step | |
| If of ConditionalStep<'state> | |
| Do of WorkflowStep<'state> list | |
| DoIf of Predicate<'state> * WorkflowStep<'state> list | |
| Eval of ('state -> WorkflowStep<'state> list) | |
type Workflow<'state> = WorkflowStep<'state> list | |
type AusState = | QLD | NSW | VIC | |
type CustomerType = SME | Resi | |
type DemoState = | |
{ | |
AusState: AusState | |
CustomerType: CustomerType | |
} | |
let isQld (state: DemoState) = state.AusState = QLD | |
let isSme (state: DemoState) = state.CustomerType = SME | |
let merge a b : Workflow<_> = a @ b | |
let intro: Workflow<DemoState> = | |
[ | |
If (isSme, BusinessAddress) | |
If (isQld, VSI) | |
Step Offer | |
] | |
let smePath = [ AccountHolder; BusinessDetails; ] |> List.map Step | |
let resiPath = [ AccountHolder; Identity; Concessions; ] |> List.map Step | |
let outro = [ Consent; Feedback; Thanks ] |> List.map Step | |
let customerJourney (state: DemoState) = | |
match state.CustomerType with | |
| SME -> smePath | |
| Resi -> resiPath | |
let combined = | |
[ | |
Do intro | |
Eval customerJourney | |
Do outro | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment