{-|
Module:      TextShow.Data.Typeable.Utils
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

Utility functions for showing data types in the @Typeable@ (or @OldTypeable@) module.
-}
module TextShow.Data.Typeable.Utils (showbArgs, showbTuple) where

import Data.Text.Lazy.Builder (Builder, singleton)

import Prelude ()
import Prelude.Compat

import TextShow.Classes (TextShow(..))

-- | Helper function for showing a list of arguments, each separated by the given
-- 'Builder'.
showbArgs :: TextShow a => Builder -> [a] -> Builder
showbArgs :: forall a. TextShow a => Builder -> [a] -> Builder
showbArgs Builder
_   []     = Builder
forall a. Monoid a => a
mempty
showbArgs Builder
_   [a
a]    = Int -> a -> Builder
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
10 a
a
showbArgs Builder
sep (a
a:[a]
as) = Int -> a -> Builder
forall a. TextShow a => Int -> a -> Builder
showbPrec Int
10 a
a Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder
sep Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [a] -> Builder
forall a. TextShow a => Builder -> [a] -> Builder
showbArgs Builder
sep [a]
as

-- | Helper function for showing a list of 'Show' instances in a tuple.
showbTuple :: TextShow a => [a] -> Builder
showbTuple :: forall a. TextShow a => [a] -> Builder
showbTuple [a]
args = Char -> Builder
singleton Char
'(' Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Builder -> [a] -> Builder
forall a. TextShow a => Builder -> [a] -> Builder
showbArgs (Char -> Builder
singleton Char
',') [a]
args Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
singleton Char
')'
{-# INLINE showbTuple #-}