From 08242e29f6878cbf514bdf68a4a7276d514a6aba Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 19 Nov 2014 18:57:58 -0400 Subject: add fallback combinator --- src/Propellor/Property.hs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Propellor') diff --git a/src/Propellor/Property.hs b/src/Propellor/Property.hs index 4b957317..9545979c 100644 --- a/src/Propellor/Property.hs +++ b/src/Propellor/Property.hs @@ -89,6 +89,15 @@ check c p = adjustProperty p $ \satisfy -> ifM (liftIO c) , return NoChange ) +-- | Tries the first property, but if it fails to work, instead uses +-- the second. +fallback :: Property -> Property -> Property +fallback p1 p2 = adjustProperty p1 $ \satisfy -> do + r <- satisfy + if r == FailedChange + then propertySatisfy p2 + else return r + -- | Marks a Property as trivial. It can only return FailedChange or -- NoChange. -- -- cgit v1.2.3