1
votes

I am having serious difficulty coming up with a definition for condition in the following code. Hoping for an example and insight:

// a computation expression builder class
type Builder() =
    .
    .
    .

    [<CustomOperation( "condition",
      MaintainsVariableSpaceUsingBind = true )>]
    member this.Condition(p, [<ProjectionParameter>] b) = 
        condition p b

let attemp = AttemptBuilder()

let test =
    attempt { let x, y = exp1, exp2
              condition booleanExpr(x, y)   
              return (x, y) }

I presume b is implicitly ( fun x, y -> booleanExpr(x, y) ). The term booleanExpr(x, y) is just some Boolean expression involving x and y.

1
What are you trying to achieve here? Also, see how to create a Minimal, Complete, and Verifiable example. - scrwtp
This is it ... on page 475 of Expert F# 4.0, you could see this example for a custom conditional operator to replace if/then. The valuecondition is not specifically defined. - Sasha Babaei

1 Answers

0
votes

Found It:

let condition p guard = ( fun () ->
    match p() with
    | Some x when guard x -> Some x
    | _ -> None )