diff --git a/src/Hedgehog/Property.fs b/src/Hedgehog/Property.fs index 2ec927c2..bdd9617d 100644 --- a/src/Hedgehog/Property.fs +++ b/src/Hedgehog/Property.fs @@ -56,15 +56,18 @@ module Property = failure let counterexample (msg : unit -> string) : Property = - Gen.constant (Journal.singleton msg, Success ()) |> ofGen + (Journal.singleton msg, Success ()) |> Gen.constant |> ofGen let private mapGen (f : Gen> -> Gen>) - (x : Property<'a>) : Property<'b> = - toGen x |> f |> ofGen + (p : Property<'a>) : Property<'b> = + p |> toGen |> f |> ofGen let map (f : 'a -> 'b) (x : Property<'a>) : Property<'b> = - (mapGen << GenTuple.mapSnd << Outcome.map) f x + f |> Outcome.map |> GenTuple.mapSnd |> mapGen <| x + + let set (a: 'a) (property : Property<'b>) : Property<'a> = + property |> map (fun _ -> a) let private bindGen (k : 'a -> Gen>) @@ -78,11 +81,11 @@ module Property = | Success x -> GenTuple.mapFst (Journal.append journal) (k x)) - let private handle (e : exn) = - Gen.constant (Journal.singletonMessage (string e), Failure) |> ofGen + let handle (e : exn) = + (Journal.singletonMessage (string e), Failure) |> Gen.constant let bind (k : 'a -> Property<'b>) (m : Property<'a>) : Property<'b> = - bindGen (fun a -> (try k a with e -> handle e) |> toGen) (toGen m) |> ofGen + m |> toGen |> bindGen (fun a -> (try k a |> toGen with e -> handle e)) |> ofGen let private printValue (value) : string = // sprintf "%A" is not prepared for printing ResizeArray<_> (C# List) so we prepare the value instead @@ -101,13 +104,11 @@ module Property = value |> prepareForPrinting |> sprintf "%A" - let private handle (e : exn) = - Gen.constant (Journal.singletonMessage (string e), Failure) |> ofGen - let forAll (k : 'a -> Property<'b>) (gen : Gen<'a>) : Property<'b> = let prepend (x : 'a) = counterexample (fun () -> printValue x) - |> bind (fun _ -> try k x with e -> handle e) + |> set x + |> bind k |> toGen gen |> Gen.bind prepend |> ofGen @@ -211,7 +212,7 @@ module Property = try success (f a) with e -> - handle e + handle e |> ofGen let reportRecheckWith (size : Size) (seed : Seed) (config : PropertyConfig) (p : Property) : Report = let args = {