let valueToState (v : 'T) : State<'T> =
let failState (err: StateError) (refail: bool) (state: State<'T>): State<'T> =
| Fulfilled _ -> Failed err
let close (state : State<'T>) : 'T option =
let condition (test: 'T -> bool) (thenExp: State<'T> -> State<'U>) (elseExp: State<'T> -> State<'U>) (state: State<'T>) : State<'U> =
let stateEffect (effect : State<'T> -> unit) (state : State<'T>) : State<'T> =
let fulfilledStateEffect (effect: 'T -> unit) (state: State<'T>) : State<'T> =
| Fulfilled v -> effect v)
let failedStateEffect (effect: StateError -> unit) (state: State<'T>) : State<'T> =
let log (state : State<'T>) : State<'T> =
printfn "[Log] Failed with %A" e
"[Log] Fulfilled with %A" v
let checkAccountExists (state : State<string>) : State<unit> =
if code = "A" || code = "B" then
let checkAccountNotExists =
| NotFound -> Fulfilled ()
| Fulfilled _ -> Failed AlreadyExists)
let insertAccount (account : unit) (state : State<unit>) : State<unit> =
printfn "Created account"
let conditionalTest (i : int) =
(fulfilledStateEffect (printfn "%i is more than 10"))
(failState (Custom (sprintf "%i is not more than 10" i)) false)
let accountInsertTest (code : string) =
printfn "conditionalTest 1"
printfn "conditionalTest 2"
printfn "accountInsertTest 1"
printfn "accountInsertTest 2"