Hoogle Search

Within LTS Haskell 24.39 (ghc-9.10.3)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. runMaybeK :: MaybeK a -> Maybe a

    unification-fd Control.Monad.MaybeK

    Execute the MaybeK and return the concrete Maybe encoding.

  2. runMaybeKT :: Applicative m => MaybeKT m a -> m (Maybe a)

    unification-fd Control.Monad.MaybeK

    Execute a MaybeKT and return the concrete Maybe encoding.

  3. toMaybeK :: Maybe a -> MaybeK a

    unification-fd Control.Monad.MaybeK

    Lift a Maybe into MaybeK.

  4. toMaybeKT :: forall (m :: Type -> Type) a . Applicative m => Maybe a -> MaybeKT m a

    unification-fd Control.Monad.MaybeK

    Lift a Maybe into an MaybeKT.

  5. catMaybes :: [Maybe a] -> [a]

    verset Verset

    The catMaybes function takes a list of Maybes and returns a list of all the Just values.

    Examples

    Basic usage:
    >>> catMaybes [Just 1, Nothing, Just 3]
    [1,3]
    
    When constructing a list of Maybe values, catMaybes can be used to return all of the "success" results (if the list is the result of a map, then mapMaybe would be more appropriate):
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
    [Just 1,Nothing,Just 3]
    
    >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
    [1,3]
    

  6. eitherToMaybe :: Either a b -> Maybe b

    verset Verset

    Given an Either, convert it to a Maybe, where Left becomes Nothing.

    \x -> eitherToMaybe (Left x) == Nothing
    \x -> eitherToMaybe (Right x) == Just x
    

  7. fromMaybe :: a -> Maybe a -> a

    verset Verset

    The fromMaybe function takes a default value and a Maybe value. If the Maybe is Nothing, it returns the default value; otherwise, it returns the value contained in the Maybe.

    Examples

    Basic usage:
    >>> fromMaybe "" (Just "Hello, World!")
    "Hello, World!"
    
    >>> fromMaybe "" Nothing
    ""
    
    Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> fromMaybe 0 (readMaybe "5")
    5
    
    >>> fromMaybe 0 (readMaybe "")
    0
    

  8. mapMaybe :: (a -> Maybe b) -> [a] -> [b]

    verset Verset

    The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list.

    Examples

    Using mapMaybe f x is a shortcut for catMaybes $ map f x in most cases:
    >>> import GHC.Internal.Text.Read ( readMaybe )
    
    >>> let readMaybeInt = readMaybe :: String -> Maybe Int
    
    >>> mapMaybe readMaybeInt ["1", "Foo", "3"]
    [1,3]
    
    >>> catMaybes $ map readMaybeInt ["1", "Foo", "3"]
    [1,3]
    
    If we map the Just constructor, the entire list should be returned:
    >>> mapMaybe Just [1,2,3]
    [1,2,3]
    

  9. readMaybe :: Read a => String -> Maybe a

    verset Verset

    Parse a string using the Read instance. Succeeds if there is exactly one valid result.

    >>> readMaybe "123" :: Maybe Int
    Just 123
    
    >>> readMaybe "hello" :: Maybe Int
    Nothing
    

  10. raiseMaybe :: X () -> Query Bool -> X ()

    xmonad-contrib XMonad.Actions.WindowGo

    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"))
    

Page 319 of many | Previous | Next