{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Util.Invisible
-- Description :  A data type to store the layout state.
-- Copyright   :  (c) 2007 Andrea Rossato, David Roundy
-- License     :  BSD-style (see xmonad/LICENSE)
--
-- Maintainer  :  andrea.rossato@unibz.it
-- Stability   :  unstable
-- Portability :  unportable
--
-- A data type to store the layout state
--
-----------------------------------------------------------------------------

module XMonad.Util.Invisible (
                             -- * Usage:
                             -- $usage
                             Invisible (..)
                            , whenIJust
                            , fromIMaybe
                            ) where

import Control.Monad.Fail

-- $usage
-- A wrapper data type to store layout state that shouldn't be persisted across
-- restarts. A common wrapped type to use is @Maybe a@.
-- Invisible derives trivial definitions for Read and Show, so the wrapped data
-- type need not do so.

newtype Invisible m a = I (m a) deriving (forall a. a -> Invisible m a
forall a b. Invisible m a -> Invisible m b -> Invisible m b
forall a b. Invisible m a -> (a -> Invisible m b) -> Invisible m b
forall {m :: * -> *}. Monad m => Applicative (Invisible m)
forall (m :: * -> *) a. Monad m => a -> Invisible m a
forall (m :: * -> *) a b.
Monad m =>
Invisible m a -> Invisible m b -> Invisible m b
forall (m :: * -> *) a b.
Monad m =>
Invisible m a -> (a -> Invisible m b) -> Invisible m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: forall a. a -> Invisible m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> Invisible m a
>> :: forall a b. Invisible m a -> Invisible m b -> Invisible m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
Invisible m a -> Invisible m b -> Invisible m b
>>= :: forall a b. Invisible m a -> (a -> Invisible m b) -> Invisible m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Invisible m a -> (a -> Invisible m b) -> Invisible m b
Monad, forall a. String -> Invisible m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall {m :: * -> *}. MonadFail m => Monad (Invisible m)
forall (m :: * -> *) a. MonadFail m => String -> Invisible m a
fail :: forall a. String -> Invisible m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> Invisible m a
MonadFail, forall a. a -> Invisible m a
forall a b. Invisible m a -> Invisible m b -> Invisible m a
forall a b. Invisible m a -> Invisible m b -> Invisible m b
forall a b. Invisible m (a -> b) -> Invisible m a -> Invisible m b
forall a b c.
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall {m :: * -> *}. Applicative m => Functor (Invisible m)
forall (m :: * -> *) a. Applicative m => a -> Invisible m a
forall (m :: * -> *) a b.
Applicative m =>
Invisible m a -> Invisible m b -> Invisible m a
forall (m :: * -> *) a b.
Applicative m =>
Invisible m a -> Invisible m b -> Invisible m b
forall (m :: * -> *) a b.
Applicative m =>
Invisible m (a -> b) -> Invisible m a -> Invisible m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
<* :: forall a b. Invisible m a -> Invisible m b -> Invisible m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
Invisible m a -> Invisible m b -> Invisible m a
*> :: forall a b. Invisible m a -> Invisible m b -> Invisible m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Invisible m a -> Invisible m b -> Invisible m b
liftA2 :: forall a b c.
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
<*> :: forall a b. Invisible m (a -> b) -> Invisible m a -> Invisible m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Invisible m (a -> b) -> Invisible m a -> Invisible m b
pure :: forall a. a -> Invisible m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Invisible m a
Applicative, forall a b. a -> Invisible m b -> Invisible m a
forall a b. (a -> b) -> Invisible m a -> Invisible m b
forall (m :: * -> *) a b.
Functor m =>
a -> Invisible m b -> Invisible m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Invisible m a -> Invisible m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Invisible m b -> Invisible m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Invisible m b -> Invisible m a
fmap :: forall a b. (a -> b) -> Invisible m a -> Invisible m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Invisible m a -> Invisible m b
Functor)

instance (Functor m, Monad m, MonadFail m) => Read (Invisible m a) where
    readsPrec :: Int -> ReadS (Invisible m a)
readsPrec Int
_ String
s = [(forall (m :: * -> *) a. MonadFail m => String -> m a
Control.Monad.Fail.fail String
"Read Invisible", String
s)]

instance Monad m => Show (Invisible m a) where
    show :: Invisible m a -> String
show Invisible m a
_ = String
""

whenIJust :: (Monad m) => Invisible Maybe a -> (a -> m ()) -> m ()
whenIJust :: forall (m :: * -> *) a.
Monad m =>
Invisible Maybe a -> (a -> m ()) -> m ()
whenIJust (I (Just a
x)) a -> m ()
f  = a -> m ()
f a
x
whenIJust (I  Maybe a
Nothing) a -> m ()
_  = forall (m :: * -> *) a. Monad m => a -> m a
return ()

fromIMaybe :: a -> Invisible Maybe a -> a
fromIMaybe :: forall a. a -> Invisible Maybe a -> a
fromIMaybe a
_ (I (Just a
x)) = a
x
fromIMaybe a
a (I  Maybe a
Nothing) = a
a