Skip to content

Instantly share code, notes, and snippets.

@Szer
Last active July 27, 2020 21:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Szer/01c7e531927b0d7326e7269b73a76346 to your computer and use it in GitHub Desktop.
Save Szer/01c7e531927b0d7326e7269b73a76346 to your computer and use it in GitHub Desktop.
Computational expression with state being passed through steps
type StepfulBuilder() =
member _.Zero() = ()
member _.Yield x = x
[<CustomOperation("toInt")>]
member inline _.ToInt(_, value) =
int value
[<CustomOperation("transform")>]
member _.Transform(x, f) =
f x
[<CustomOperation("print")>]
member _.Print(x) =
printfn "%A" x
x
let steps = StepfulBuilder()
let flow =
steps {
toInt "1"
transform (fun x -> x + 5)
print
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment