From 670a0719ddcdb4d95ae598f960394acd6d0fc81e Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 25 Nov 2016 14:06:32 -0800 Subject: [PATCH] [XMonad] Add utility function section, write >>=/ --- dotfiles/xmonad/xmonad.hs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/dotfiles/xmonad/xmonad.hs b/dotfiles/xmonad/xmonad.hs index d8246401..56b85858 100644 --- a/dotfiles/xmonad/xmonad.hs +++ b/dotfiles/xmonad/xmonad.hs @@ -62,6 +62,24 @@ main = xmonad $ def , keys = customKeys (const []) addKeys } where x +++ y = mappend y x + + +-- Utility functions + +fork :: Monad m => (i -> m a) -> (i -> m b) -> i -> m (a, b) +fork a b input = do + resA <- a input + resB <- b input + return (resA, resB) + +tee :: Monad m => (i -> m a) -> (i -> m b) -> i -> m a +tee = (fmap . fmap . fmap) (fmap fst) fork + +(>>=/) :: Monad m => m a -> (a -> m b) -> m a +(>>=/) a = (a >>=) . tee return + +findM :: (Monad m) => (a -> m (Maybe b)) -> [a] -> m (Maybe b) +findM f = runMaybeT . msum . map (MaybeT . f) -- Selectors @@ -145,13 +163,9 @@ selectToggle = togglesMap >>= DM.menuMapArgs "rofi" ["-dmenu", "-i"] >>= toggleInState :: (Transformer t Window) => t -> Maybe Bool -> X Bool toggleInState t s = fmap (/= s) (isToggleActive t) -whenB b a = do - when b a - return b - setToggleActive' toggle active = - toggleInState toggle (Just active) >>= - flip whenB (sendMessage $ Toggle toggle) + toggleInState toggle (Just active) >>=/ + flip when (sendMessage $ Toggle toggle) -- Ambiguous type reference without signature setToggleActive :: (Transformer t Window) => t -> Bool -> X () @@ -196,9 +210,6 @@ myLayoutHook = avoidStruts . minimize . boringAuto . mkToggle1 MIRROR . -- WindowBringer -findM :: (Monad m) => (a -> m (Maybe b)) -> [a] -> m (Maybe b) -findM f = runMaybeT . msum . map (MaybeT . f) - myWindowBringerConfig = WindowBringerConfig { menuCommand = "rofi" , menuArgs = ["-dmenu", "-i"]