Skip to content

Commit cf98dc7

Browse files
committed
New whileM and unlessM functions
1 parent 0dccc02 commit cf98dc7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/HaskellWorks/Control/Monad.hs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
module HaskellWorks.Control.Monad
2-
( repeatNUntilM_,
2+
( whileM,
3+
unlessM,
4+
5+
repeatNUntilM_,
36
repeatNWhileM_,
47
) where
58

69
import HaskellWorks.Prelude
710

11+
whileM :: Monad m => m Bool -> m ()
12+
whileM act = do
13+
b <- act
14+
when b $ whileM act
15+
16+
unlessM :: Monad m => m Bool -> m ()
17+
unlessM act = do
18+
b <- act
19+
unless b $ unlessM act
20+
821
-- | Repeat an action n times until the action returns True.
922
repeatNUntilM_ :: ()
1023
=> Monad m

0 commit comments

Comments
 (0)