{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module XMonad.Util.Invisible (
Invisible (..)
, whenIJust
, fromIMaybe
) where
import Control.Monad.Fail
newtype Invisible m a = I (m a) deriving (Applicative (Invisible m)
Applicative (Invisible m) =>
(forall a b.
Invisible m a -> (a -> Invisible m b) -> Invisible m b)
-> (forall a b. Invisible m a -> Invisible m b -> Invisible m b)
-> (forall a. a -> Invisible m a)
-> Monad (Invisible m)
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
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
Invisible m a -> (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 -> Invisible m b -> Invisible m b
>> :: forall a b. Invisible m a -> Invisible m b -> Invisible m b
$creturn :: forall (m :: * -> *) a. Monad m => a -> Invisible m a
return :: forall a. a -> Invisible m a
Monad, Monad (Invisible m)
Monad (Invisible m) =>
(forall a. String -> Invisible m a) -> MonadFail (Invisible m)
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
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> Invisible m a
fail :: forall a. String -> Invisible m a
MonadFail, Functor (Invisible m)
Functor (Invisible m) =>
(forall a. a -> Invisible m a)
-> (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 a b. Invisible m a -> Invisible m b -> Invisible m b)
-> (forall a b. Invisible m a -> Invisible m b -> Invisible m a)
-> Applicative (Invisible m)
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
$cpure :: forall (m :: * -> *) a. Applicative m => a -> Invisible m a
pure :: forall a. a -> Invisible m a
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
Invisible m (a -> b) -> Invisible m a -> Invisible m b
<*> :: forall a b. Invisible m (a -> b) -> Invisible m a -> Invisible m b
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
liftA2 :: forall a b c.
(a -> b -> c) -> Invisible m a -> Invisible m b -> Invisible m c
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
Invisible m a -> Invisible m b -> Invisible m b
*> :: 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 a
<* :: forall a b. Invisible m a -> Invisible m b -> Invisible m a
Applicative, (forall a b. (a -> b) -> Invisible m a -> Invisible m b)
-> (forall a b. a -> Invisible m b -> Invisible m a)
-> Functor (Invisible m)
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
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> Invisible m a -> Invisible m b
fmap :: forall a b. (a -> b) -> Invisible m a -> Invisible m b
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> Invisible m b -> Invisible m a
<$ :: forall a b. a -> Invisible m b -> Invisible m a
Functor)
instance (Functor m, Monad m, MonadFail m) => Read (Invisible m a) where
readsPrec :: Int -> ReadS (Invisible m a)
readsPrec Int
_ String
s = [(String -> Invisible m a
forall a. String -> Invisible m a
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 ()
_ = () -> m ()
forall a. a -> m a
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