Skip to content

Commit 3fa7333

Browse files
authored
Merge pull request #14 from haskell-works/newhoggy/new-whileNothingM-function
New `whileNothingM` function
2 parents 416e254 + ed41e02 commit 3fa7333

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/HaskellWorks/Control/Monad.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module HaskellWorks.Control.Monad
22
( whileM,
33
unlessM,
44

5+
whileNothingM,
6+
57
repeatNUntilM_,
68
repeatNWhileM_,
79
) where
@@ -18,6 +20,10 @@ unlessM act = do
1820
b <- act
1921
unless b $ unlessM act
2022

23+
whileNothingM :: Monad m => m (Maybe a) -> m a
24+
whileNothingM act =
25+
act >>= maybe (whileNothingM act) pure
26+
2127
-- | Repeat an action n times until the action returns True.
2228
repeatNUntilM_ :: ()
2329
=> Monad m

0 commit comments

Comments
 (0)