diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/math/random.lux | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index b8db79ccb..28751e125 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -20,6 +20,7 @@ [stack #+ Stack] [row #+ Row] (tree [finger #+ Tree]))) + (type [refinement #+ Refiner Refined]) )) (type: #export #rec PRNG @@ -66,6 +67,18 @@ (wrap sample) (filter pred gen)))) +(def: #export (refine refiner gen) + {#.doc "Retries the generator until the output can be refined."} + (All [t r] (-> (Refiner t r) (Random t) (Random (Refined t r)))) + (do Monad<Random> + [sample gen] + (case (refiner sample) + (#.Some refined) + (wrap refined) + + #.None + (refine refiner gen)))) + (def: #export bool (Random Bool) (function (_ prng) |