Skip to content

Commit

Permalink
Change ListGen.traverse from monadic to applicative
Browse files Browse the repository at this point in the history
  • Loading branch information
TysonMN committed Dec 30, 2021
1 parent d55bbe8 commit 6ff78f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Version ?.?.?

- Add `Tree.apply`. Change `Gen.apply` from monadic to applicative. Revert runtime optimization of `Gen.integral`. ([#398][398], [@TysonMN][TysonMN])
- Change `ListGen.traverse` from monadic to applicative. ([#399][399], [@TysonMN][TysonMN])

## Version 0.12.0 (2021-12-12)

Expand Down Expand Up @@ -189,6 +190,8 @@
[porges]:
https://github.com/porges

[399]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/399
[398]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/398
[386]:
Expand Down
18 changes: 9 additions & 9 deletions src/Hedgehog/ListGen.fs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Hedgehog.ListGen


let traverse (f: 'a -> Gen<'b>) (ma: list<'a>) : Gen<list<'b>> =
let rec loop input output =
match input with
| [] -> output |> List.rev |> Gen.constant
| a :: input ->
gen {
let! b = f a
return! loop input (b :: output)
}
loop ma []
List.empty
|> Gen.constant
|> List.fold (fun glb a ->
(fun list b -> List.append list [b])
|> Gen.constant
|> Gen.apply glb
|> Gen.apply (f a))
<| ma

let sequence (gens : List<Gen<'a>>) : Gen<List<'a>> =
gens |> traverse id

0 comments on commit 6ff78f5

Please sign in to comment.