maybe package:xmonad-contrib

The maybe function takes a default value, a function, and a Maybe value. If the Maybe value is Nothing, the function returns the default value. Otherwise, it applies the function to the value inside the Just and returns the result.

Examples

Basic usage:
>>> maybe False odd (Just 3)
True
>>> maybe False odd Nothing
False
Read an integer from a string using readMaybe. If we succeed, return twice the integer; that is, apply (*2) to it. If instead we fail to parse an integer, return 0 by default:
>>> import Text.Read ( readMaybe )

>>> maybe 0 (*2) (readMaybe "5")
10

>>> maybe 0 (*2) (readMaybe "")
0
Apply show to a Maybe Int. If we have Just n, we want to show the underlying Int n. But if we have Nothing, we return the empty string instead of (for example) "Nothing":
>>> maybe "" show (Just 5)
"5"

>>> maybe "" show Nothing
""
The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error. The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.
manageDebug only if the user requested it with debugNextManagedWindow.
A variant of MaybeManageHook that additionally may or may not make changes to the WindowSet.
A ManageHook that may or may not have been executed; the outcome is embedded in the Maybe
raiseMaybe queries all Windows based on a boolean provided by the user. Currently, there are 3 such useful booleans defined in XMonad.ManageHook: title, resource, className. Each one tests based pretty much as you would think. ManageHook also defines several operators, the most useful of which is (=?). So a useful test might be finding a Window whose class is Firefox. Firefox 3 declares the class "Firefox", so you'd want to pass in a boolean like (className =? "Firefox"). If the boolean returns True on one or more windows, then XMonad will quickly make visible the first result. If no Window meets the criteria, then the first argument comes into play. The first argument is an arbitrary IO function which will be executed if the tests fail. This is what enables runOrRaise to use raiseMaybe: it simply runs the desired program if it isn't found. But you don't have to do that. Maybe you want to do nothing if the search fails (the definition of raise), or maybe you want to write to a log file, or call some prompt function, or something crazy like that. This hook gives you that flexibility. You can do some cute things with this hook. Suppose you want to do the same thing for Mutt which you just did for Firefox - but Mutt runs inside a terminal window? No problem: you search for a terminal window calling itself "mutt", and if there isn't you run a terminal with a command to run Mutt! Here's an example (borrowing runInTerm from XMonad.Util.Run):
, ((modm, xK_m), raiseMaybe (runInTerm "-title mutt" "mutt") (title =? "mutt"))
See raiseMaybe. raiseNextMaybe is an alternative version that allows cycling through the matching windows. If the focused window matches the query the next matching window is raised. If no matches are found the function f is executed.
See raiseMaybe and raiseNextMaybe. In addition to all of the options offered by raiseNextMaybe raiseNextMaybeCustomFocus allows the user to supply the function that should be used to shift the focus to any window that is found.
ewmhDesktopsManageHook as a MaybeManageHook for use with composeOne. Returns Nothing if the window didn't indicate any desktop preference, otherwise Just (even if the preferred desktop was out of bounds).
handleMessOrMaybeModifyIt allows you to intercept messages sent to the underlying layout, in order to have an effect in the X monad, alter the layout modifier state, or produce a modified message to be passed on to the underlying layout. The default implementation of handleMessOrMaybeModifyIt simply passes on the message to handleMess.