aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2017-05-07 19:51:36 -0400
committerEduardo Julian2017-05-07 19:51:36 -0400
commit29c0e991917ac744b856919331ff039d04d5832b (patch)
treefa31a2aa4bcfd6987328c516ec8611b3100ab836 /stdlib/source
parent08eb05f23914194c3adcc141664d4c2d7d88978c (diff)
- Added "while" and "do-while" loops for stateful computations.
- Improved tests for lux/control/state.
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/control/state.lux16
1 files changed, 16 insertions, 0 deletions
diff --git a/stdlib/source/lux/control/state.lux b/stdlib/source/lux/control/state.lux
index 9ee12e93d..37135ac06 100644
--- a/stdlib/source/lux/control/state.lux
+++ b/stdlib/source/lux/control/state.lux
@@ -122,3 +122,19 @@
(do Monad<M>
[a ma]
(wrap [state a]))))
+
+(def: #export (while condition body)
+ (All [s] (-> (State s Bool) (State s Unit) (State s Unit)))
+ (do Monad<State>
+ [execute? condition]
+ (if execute?
+ (do @
+ [_ body]
+ (while condition body))
+ (wrap []))))
+
+(def: #export (do-while condition body)
+ (All [s] (-> (State s Bool) (State s Unit) (State s Unit)))
+ (do Monad<State>
+ [_ body]
+ (while condition body)))