diff options
author | Eduardo Julian | 2017-05-07 19:51:36 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-05-07 19:51:36 -0400 |
commit | 29c0e991917ac744b856919331ff039d04d5832b (patch) | |
tree | fa31a2aa4bcfd6987328c516ec8611b3100ab836 /stdlib/source | |
parent | 08eb05f23914194c3adcc141664d4c2d7d88978c (diff) |
- Added "while" and "do-while" loops for stateful computations.
- Improved tests for lux/control/state.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/state.lux | 16 |
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))) |