diff --git a/CHANGES.md b/CHANGES.md index b0a5879..e720024 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -68,6 +68,11 @@ * Added `withUnfocused` function to `XMonad.Operations`, allowing for `X` operations to be applied to unfocused windows. + * Made `(<&&>)` and `(<||>)` non-strict in their right operand; i.e., + these operators now implement short-circuit evaluation so the right + operand is evaluated only if the left operand does not suffice to + determine the result. + ## 0.15 (September 30, 2018) * Reimplement `sendMessage` to deal properly with windowset changes made diff --git a/src/XMonad/ManageHook.hs b/src/XMonad/ManageHook.hs index ac44e52..1a21f2a 100644 --- a/src/XMonad/ManageHook.hs +++ b/src/XMonad/ManageHook.hs @@ -61,11 +61,15 @@ infixr 3 <&&>, <||> -- | '&&' lifted to a 'Monad'. (<&&>) :: Monad m => m Bool -> m Bool -> m Bool -(<&&>) = liftM2 (&&) +(<&&>) x y = ifM x y (pure False) -- | '||' lifted to a 'Monad'. (<||>) :: Monad m => m Bool -> m Bool -> m Bool -(<||>) = liftM2 (||) +(<||>) x y = ifM x (pure True) y + +-- | If-then-else lifted to a 'Monad'. +ifM :: Monad m => m Bool -> m a -> m a -> m a +ifM mb t f = mb >>= \b -> if b then t else f -- | Return the window title. title :: Query String