File tree Expand file tree Collapse file tree 3 files changed +17
-11
lines changed
Expand file tree Collapse file tree 3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ https://github.com/hedgehogqa/fsharp-hedgehog/blob/master/doc/index.md
3333 <Compile Include =" OptionTree.fs" />
3434 <Compile Include =" Range.fs" />
3535 <Compile Include =" Random.fs" />
36+ <Compile Include =" ListRandom.fs" />
3637 <Compile Include =" Shrink.fs" />
3738 <Compile Include =" Gen.fs" />
3839 <Compile Include =" ListGen.fs" />
Original file line number Diff line number Diff line change 1+ [<RequireQualifiedAccess>]
2+ module Hedgehog.ListRandom
3+
4+ let traverse ( f : 'a -> Random < 'b >) ( list : List < 'a >) : Random < List < 'b >> =
5+ let rec loop input output =
6+ match input with
7+ | [] -> output |> List.rev |> Random.constant
8+ | a :: input ->
9+ random {
10+ let! b = f a
11+ return ! loop input ( b :: output)
12+ }
13+ loop list []
14+
15+ let sequence ( randoms : List < Random < 'a >>) : Random < List < 'a >> =
16+ randoms |> traverse id
Original file line number Diff line number Diff line change @@ -51,17 +51,6 @@ module Random =
5151 let bind ( f : 'a -> Random < 'b >) ( r : Random < 'a >) : Random < 'b > =
5252 r |> map f |> join
5353
54- let replicate ( times : int ) ( r : Random < 'a >) : Random < List < 'a >> =
55- Random ( fun seed0 size ->
56- let rec loop seed k acc =
57- if k <= 0 then
58- acc
59- else
60- let seed1 , seed2 = Seed.split seed
61- let x = unsafeRun seed1 size r
62- loop seed2 ( k - 1 ) ( x :: acc)
63- loop seed0 times [])
64-
6554 type Builder internal () =
6655 member __.Return ( x : 'a ) : Random < 'a > =
6756 constant x
You can’t perform that action at this time.
0 commit comments