Skip to content

Commit

Permalink
Merge pull request #14 from haskell-works/newhoggy/new-whileNothingM-…
Browse files Browse the repository at this point in the history
…function

New `whileNothingM` function
  • Loading branch information
newhoggy authored Jan 5, 2025
2 parents 416e254 + ed41e02 commit 3fa7333
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/HaskellWorks/Control/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module HaskellWorks.Control.Monad
( whileM,
unlessM,

whileNothingM,

repeatNUntilM_,
repeatNWhileM_,
) where
Expand All @@ -18,6 +20,10 @@ unlessM act = do
b <- act
unless b $ unlessM act

whileNothingM :: Monad m => m (Maybe a) -> m a
whileNothingM act =
act >>= maybe (whileNothingM act) pure

-- | Repeat an action n times until the action returns True.
repeatNUntilM_ :: ()
=> Monad m
Expand Down

0 comments on commit 3fa7333

Please sign in to comment.