Skip to content

Instantly share code, notes, and snippets.

@matthewcrews
Created January 16, 2021 22:42
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 matthewcrews/eaa2bbc7b74e1515dbc957a17bfcf0fe to your computer and use it in GitHub Desktop.
Save matthewcrews/eaa2bbc7b74e1515dbc957a17bfcf0fe to your computer and use it in GitHub Desktop.
type BuilderTest () =
member this.Yield (evalResult: bool) =
evalResult
member this.For(source: seq<'a>, body:'a -> seq<'b * bool>) =
source
|> Seq.collect (fun x -> body x |> Seq.map (fun (idx, expr) -> (x, idx), expr))
member this.For(source: seq<'a>, body:'a -> bool) =
source |> Seq.map (fun x -> x, body x)
member this.Run(source: seq<'a * bool>) =
source |> Seq.map (fun (n, c) -> n, c)
[<CustomOperation("requires")>]
member this.Requires(a: bool, b: bool) =
a && b
let values = [1..10]
let builderTest = BuilderTest ()
let test =
builderTest {
for x in values ->
let z = x > 2
z requires true
}
@matthewcrews
Copy link
Author

This example is dumb but it illustrates what I would like to be able to accomplish with as little code as possible. The real application is for the Flips library. Line 27 is what we want to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment