Skip to content

Commit

Permalink
Change Gen.apply from monadic to applicative
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Dec 29, 2021
1 parent 3703ef2 commit 5f1ab55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Version ?.?.?

- Add `Tree.apply` ([#398][398], [@TysonMN][TysonMN])
- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. ([#398][398], [@TysonMN][TysonMN])

## Version 0.12.0 (2021-12-12)

Expand Down
7 changes: 5 additions & 2 deletions src/Hedgehog/Gen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ module Gen =
let bind (k : 'a -> Gen<'b>) (m : Gen<'a>) : Gen<'b> =
toRandom m |> bindRandom (toRandom << k) |> ofRandom

let private applyRandom (rta : Random<Tree<'a>>) (rtf : Random<Tree<'a -> 'b>>) : Random<Tree<'b>> =
rtf |> Random.bind (fun tf ->
rta |> Random.map (fun ta -> Tree.apply ta tf))

let apply (ga : Gen<'a>) (gf : Gen<'a -> 'b>) : Gen<'b> =
gf |> bind (fun f ->
ga |> map f)
applyRandom (toRandom ga) (toRandom gf) |> ofRandom

let map2 (f : 'a -> 'b -> 'c) (ga : Gen<'a>) (gb : Gen<'b>) : Gen<'c> =
constant f
Expand Down

0 comments on commit 5f1ab55

Please sign in to comment.