-
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.
replaced Random.replicate with ListRandom traverse and sequence
- Loading branch information
Showing
4 changed files
with
23 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[<RequireQualifiedAccess>] | ||
module Hedgehog.ListRandom | ||
|
||
let traverse (f: 'a -> Random<'b>) (list: List<'a>) : Random<List<'b>> = | ||
let rec loop input output = | ||
match input with | ||
| [] -> output |> List.rev |> Random.constant | ||
| a :: input -> | ||
random { | ||
let! b = f a | ||
return! loop input (b :: output) | ||
} | ||
loop list [] | ||
|
||
let sequence (randoms : List<Random<'a>>) : Random<List<'a>> = | ||
randoms |> traverse id |
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