-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change ListGen.traverse from monadic to applicative
- Loading branch information
Showing
2 changed files
with
12 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |