X.H.ManageHelpers: Add new operators (#633)

Closes: #628
This commit is contained in:
Aleksei Pirogov
2021-10-26 22:53:52 +03:00
committed by GitHub
parent e1f4f77346
commit 8b6f17ba66
2 changed files with 30 additions and 1 deletions

View File

@@ -520,6 +520,9 @@
- Added `windowTag` - Added `windowTag`
- Added `(^?)`, `(~?)` and `($?)` operators as infix versions of `isPrefixOf`, `isInfixOf`
and `isSuffixOf` working with `ManageHook`s.
* `XMonad.Util.EZConfig` * `XMonad.Util.EZConfig`
- Added support for XF86Bluetooth. - Added support for XF86Bluetooth.

View File

@@ -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 ( module XMonad.Hooks.ManageHelpers (
Side(..), Side(..),
composeOne, composeOne,
(-?>), (/=?), (<==?), (</=?), (-->>), (-?>>), (-?>), (/=?), (^?), (~?), ($?), (<==?), (</=?), (-->>), (-?>>),
currentWs, currentWs,
windowTag, windowTag,
isInProperty, isInProperty,
@@ -95,6 +109,18 @@ infixr 0 -?>, -->>, -?>>
(/=?) :: (Eq a, Functor m) => m a -> a -> m Bool (/=?) :: (Eq a, Functor m) => m a -> a -> m Bool
q /=? x = fmap (/= x) q 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 -- | q <==? x. if the result of q equals x, return True grouped with q
(<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a) (<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a)
q <==? x = fmap (`eq` x) q q <==? x = fmap (`eq` x) q