{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds         #-}

{-# OPTIONS_GHC -Wno-orphans #-}
{-|
Module:      TextShow.Data.Functor.Trans
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

'TextShow' instances for functor transformers.

Note that :

* An instance for 'Identity' is found in @text-show@, since it is a part of
  @base-4.8.0.0@ and later.

* Instances for 'Compose', 'Product', and 'Sum' are found in @text-show@, since they
  are part of @base-4.9.0.0@ and later.

/Since: 2/
-}
module TextShow.Data.Functor.Trans () where

import Data.Functor.Constant (Constant(..))
import Data.Functor.Reverse  (Reverse(..))

import TextShow (TextShow(..), TextShow1(..), TextShow2(..),
                 Builder, showbPrec1, showbUnaryWith)
import TextShow.Utils (liftShowbUnaryWith)

-- | Convert a 'Constant' value to a 'Builder' with the given show function
-- and precedence.
liftShowbConstantPrec :: (Int -> a -> Builder) -> Int -> Constant a b -> Builder
liftShowbConstantPrec :: forall {k} a (b :: k).
(Int -> a -> Builder) -> Int -> Constant a b -> Builder
liftShowbConstantPrec Int -> a -> Builder
sp Int
p (Constant a
x) = forall a. (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
showbUnaryWith Int -> a -> Builder
sp Builder
"Constant" Int
p a
x
{-# INLINE liftShowbConstantPrec #-}

-- | /Since: 2/
instance TextShow a => TextShow (Constant a b) where
    showbPrec :: Int -> Constant a b -> Builder
showbPrec = forall {k} a (b :: k).
(Int -> a -> Builder) -> Int -> Constant a b -> Builder
liftShowbConstantPrec forall a. TextShow a => Int -> a -> Builder
showbPrec
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow a => TextShow1 (Constant a) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Constant a a -> Builder
liftShowbPrec Int -> a -> Builder
_ [a] -> Builder
_ = forall {k} a (b :: k).
(Int -> a -> Builder) -> Int -> Constant a b -> Builder
liftShowbConstantPrec forall a. TextShow a => Int -> a -> Builder
showbPrec
    {-# INLINE liftShowbPrec #-}

-- | /Since: 2/
instance TextShow2 Constant where
    liftShowbPrec2 :: forall a b.
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> Int
-> Constant a b
-> Builder
liftShowbPrec2 Int -> a -> Builder
sp [a] -> Builder
_ Int -> b -> Builder
_ [b] -> Builder
_ = forall {k} a (b :: k).
(Int -> a -> Builder) -> Int -> Constant a b -> Builder
liftShowbConstantPrec Int -> a -> Builder
sp
    {-# INLINE liftShowbPrec2 #-}

-- | /Since: 2/
instance (TextShow1 f, TextShow a) => TextShow (Reverse f a) where
    showbPrec :: Int -> Reverse f a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow1 f => TextShow1 (Reverse f) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Reverse f a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl Int
p (Reverse f a
x) = forall (m :: * -> *) a.
TextShow1 m =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m a -> Builder
liftShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl Builder
"Reverse" Int
p f a
x
    {-# INLINE liftShowbPrec #-}