Created
January 16, 2021 22:42
-
-
Save matthewcrews/eaa2bbc7b74e1515dbc957a17bfcf0fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.