From ed41e02f31eda31363e0f9173c46efafe436d673 Mon Sep 17 00:00:00 2001 From: John Ky Date: Sun, 5 Jan 2025 23:30:16 +1100 Subject: [PATCH] New whileNothingM function --- src/HaskellWorks/Control/Monad.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/HaskellWorks/Control/Monad.hs b/src/HaskellWorks/Control/Monad.hs index c3d97f0..0b12ed1 100644 --- a/src/HaskellWorks/Control/Monad.hs +++ b/src/HaskellWorks/Control/Monad.hs @@ -2,6 +2,8 @@ module HaskellWorks.Control.Monad ( whileM, unlessM, + whileNothingM, + repeatNUntilM_, repeatNWhileM_, ) where @@ -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