Created
December 9, 2016 03:12
-
-
Save nightroman/7b0aab3b3bc0d4b4e54024bc1424ab80 to your computer and use it in GitHub Desktop.
This file contains 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
// sequence of steps | |
type Step = | |
| Next | |
| Ask1 of string ref | |
| Ask2 of string ref | |
let steps = seq { | |
printfn "step 0" | |
yield Next | |
printfn "step 1" | |
let ask1 = ref "" | |
yield Ask1 ask1 | |
if !ask1 = "n" then () else | |
printfn "step 2" | |
let ask2 = ref "" | |
yield Ask2 ask2 | |
if !ask2 = "c" then | |
printfn "step 3 custom" | |
yield Next | |
printfn "step 4 extra" | |
else | |
printfn "step 3 default" | |
} | |
// go default steps | |
printfn "--- default steps" | |
for step in steps do () | |
// go with a custom step | |
printfn "--- stop at Ask1" | |
for step in steps do | |
match step with | |
| Ask1 res -> res := "n" | |
| _ -> () | |
// go with a custom step | |
printfn "--- custom at Ask2" | |
for step in steps do | |
match step with | |
| Ask2 res -> res := "c" | |
| _ -> () | |
// go to Ask2 then pause and continue | |
printfn "--- pause and continue" | |
let it = steps.GetEnumerator () | |
let rec step () = | |
if it.MoveNext () then | |
match it.Current with | |
| Ask2 _ -> () | |
| _ -> step () | |
step () | |
printfn "pause" | |
while it.MoveNext () do () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment