diff --git a/CHANGES.md b/CHANGES.md index 84aaf5c3..8ea9fd13 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -520,6 +520,9 @@ - Added `windowTag` + - Added `(^?)`, `(~?)` and `($?)` operators as infix versions of `isPrefixOf`, `isInfixOf` + and `isSuffixOf` working with `ManageHook`s. + * `XMonad.Util.EZConfig` - Added support for XF86Bluetooth. diff --git a/XMonad/Hooks/ManageHelpers.hs b/XMonad/Hooks/ManageHelpers.hs index bbd392b1..b2ae327a 100644 --- a/XMonad/Hooks/ManageHelpers.hs +++ b/XMonad/Hooks/ManageHelpers.hs @@ -25,11 +25,25 @@ -- > ], -- > ... -- > } +-- +-- Here's how you can define more helpers like the ones from this module: +-- +-- > -- some function you want to transform into an infix operator +-- > f :: a -> b -> Bool +-- > +-- > -- a new helper +-- > q ***? x = fmap (\a -> f a x) q +-- > -- or +-- > q ***? x = fmap (`f` x) q +-- +-- Any existing operator can be "lifted" in the same way: +-- +-- > q ++? x = fmap (++ x) q module XMonad.Hooks.ManageHelpers ( Side(..), composeOne, - (-?>), (/=?), (<==?), (>), (-?>>), + (-?>), (/=?), (^?), (~?), ($?), (<==?), (>), (-?>>), currentWs, windowTag, isInProperty, @@ -95,6 +109,18 @@ infixr 0 -?>, -->>, -?>> (/=?) :: (Eq a, Functor m) => m a -> a -> m Bool q /=? x = fmap (/= x) q +-- | q ^? x. if the result of q 'isPrefixOf' x, return True +(^?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool +q ^? x = fmap (`isPrefixOf` x) q + +-- | q ~? x. if the result of q 'isSuffixOf' x, return True +(~?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool +q ~? x = fmap (`isInfixOf` x) q + +-- | q $? x. if the result of q 'isSuffixOf' x, return True +($?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool +q $? x = fmap (`isSuffixOf` x) q + -- | q <==? x. if the result of q equals x, return True grouped with q (<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a) q <==? x = fmap (`eq` x) q