Skip to content

Instantly share code, notes, and snippets.

@medigor
Forked from Szer/stepfulBuilder.fs
Created April 30, 2020 15:16
Show Gist options
  • Save medigor/84a90c06fa994a2be6ec7b7838704ddc to your computer and use it in GitHub Desktop.
Save medigor/84a90c06fa994a2be6ec7b7838704ddc 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