Reputation: 11570
I need help understanding how "<|" behaves for the following code:
Prop.forAll fiveAndThrees <| fun number ->
let actual = transform number
let expected = "FizzBuzz"
expected = actual
The documentation says the following:
Passes the result of the expression on the right side to the function on left side (backward pipe operator).
fiveAndThrees is a NOT a function but instead a value and it's on the left side of the operator.
I interpret the above definition as:
Take an input called "number" and feed it into the "transform" function. However, if we're passing the result of the expression on the right side to the function on the left side, then when and how does the input (i.e. number) actually get initialized?
I just don't see it.
The full test is the following:
[<Fact>]
let ``FizzBuzz.transform returns FizzBuzz`` () =
let fiveAndThrees = Arb.generate<int> |> Gen.map ((*) (3 * 5))
|> Arb.fromGen
Prop.forAll fiveAndThrees <| fun number ->
let actual = transform number
let expected = "FizzBuzz"
expected = actual
The function to be tested is the following:
let transform number =
match number % 3, number % 5 with
| 0, 0 -> "FizzBuzz"
| _, 0 -> "Buzz"
| 0, _ -> "Fizz"
| _ -> number.ToString()
Upvotes: 1
Views: 99
Reputation: 144226
<|
is an operator which binds less tightly than function application, so
Prop.forAll fiveAndThrees <| fun number -> ...
is parsed as
(Prop.forAll fiveAndThrees) <| fun number -> ...
Prop.forAll takes two parameters, an Arbitrary<T>
and a function T -> Testable
so Prop.forAll fiveAndThrees
is a function to which the right-hand side is passed.
Upvotes: 4