X.H.ManageHelpers: Flip logic for (^?), (~?), and ($?)

This changes how the "is*Of" infix operators are hoisted into the
ManageHook context.  Instead of `q ~? x` being a lifted version of
`isPrefixOf q x` we instead let it be a lift of `isPrefixOf x q`.

While this obviously does not matter for symmetric operators like `(==)`
and `(/=)`, for `isInfixOf` it is rather essential.  The reason for that
is that the given `q` on the left side is an atom that can't (shouldn't)
be changed (by the user) and we only have control over the right hand
side.  Otherwise, things like

    title ~? "foo"

would read "only match if `title` is an infix of `foo`" instead of the
much more useful "only match if `foo` is an infix of `title`".

Fixes: 8b6f17ba66
This commit is contained in:
slotThe
2021-11-17 19:58:32 +01:00
parent e82a8b8849
commit 90a96dee49
2 changed files with 14 additions and 9 deletions

View File

@@ -25,7 +25,12 @@
* `XMonad.Util.EZConfig`
- Added support for Modifier Keys `KeySym`s for Emacs-like `additionalKeysP`
- Added support for Modifier Keys `KeySym`s for Emacs-like `additionalKeysP`.
* `XMonad.Hooks.ManageHelpers`
- Flipped how `(^?)`, `(~?)`, and `($?)` work to more accurately
reflect how one uses these operators.
## 0.17.0 (October 27, 2021)

View File

@@ -32,9 +32,9 @@
-- > f :: a -> b -> Bool
-- >
-- > -- a new helper
-- > q ***? x = fmap (\a -> f a x) q
-- > q ***? x = fmap (\a -> f a x) q -- or: (\b -> f x b)
-- > -- or
-- > q ***? x = fmap (`f` x) q
-- > q ***? x = fmap (`f` x) q -- or: (x `f`)
--
-- Any existing operator can be "lifted" in the same way:
--
@@ -109,17 +109,17 @@ 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
-- | q ^? x. if the result of @x `isPrefixOf` q@, return True
(^?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool
q ^? x = fmap (`isPrefixOf` x) q
q ^? x = fmap (x `isPrefixOf`) q
-- | q ~? x. if the result of q 'isSuffixOf' x, return True
-- | q ~? x. if the result of @x `isInfixOf` q@, return True
(~?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool
q ~? x = fmap (`isInfixOf` x) q
q ~? x = fmap (x `isInfixOf`) q
-- | q $? x. if the result of q 'isSuffixOf' x, return True
-- | q $? x. if the result of @x `isSuffixOf` q@, return True
($?) :: (Eq a, Functor m) => m [a] -> [a] -> m Bool
q $? x = fmap (`isSuffixOf` x) q
q $? x = fmap (x `isSuffixOf`) 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)