Skip to content

Instantly share code, notes, and snippets.

@nightroman
Created December 9, 2016 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightroman/7b0aab3b3bc0d4b4e54024bc1424ab80 to your computer and use it in GitHub Desktop.
Save nightroman/7b0aab3b3bc0d4b4e54024bc1424ab80 to your computer and use it in GitHub Desktop.
// 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