aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2018-07-03 23:44:12 -0400
committerEduardo Julian2018-07-03 23:44:12 -0400
commit8bfbd5f1c911bdc3266d08c156bf34de1eb8c759 (patch)
tree93c74a3e186854ec5eea6fed0e3a902e4048ad35 /stdlib
parent38ce556c6e3d21acdf53d6f8e9cfd80903360c8c (diff)
- Can now refine random generators.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/math/random.lux13
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)