summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-02 16:10:52 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-02 16:12:31 -0400
commite19dc8554723a148e6b809da4989a747f3aa925e (patch)
treee55363162c701f5250beae46323aa8e0a1a65ccb /Utility
parentfb68a7881f725a7b097f8b0f1b347f24dfea5d59 (diff)
factor out untilTrue
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Conditional.hs6
1 files changed, 6 insertions, 0 deletions
diff --git a/Utility/Conditional.hs b/Utility/Conditional.hs
index 85e39ec64..7a0df4b48 100644
--- a/Utility/Conditional.hs
+++ b/Utility/Conditional.hs
@@ -9,6 +9,12 @@ module Utility.Conditional where
import Control.Monad (when, unless)
+untilTrue :: Monad m => [v] -> (v -> m Bool) -> m Bool
+untilTrue [] _ = return False
+untilTrue (v:vs) a = do
+ ok <- a v
+ if ok then return ok else untilTrue vs a
+
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a