    {-|
    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 :: Builder -> [a] -> Builder
    showbArgs _   []     = Builder
    forall a. Monoid a => a
    mempty
    showbArgs _   [a :: a
    a]    = Int -> a -> Builder
    forall a. TextShow a => Int -> a -> Builder
    showbPrec 10 a
    a
    showbArgs sep :: Builder
    sep (a :: a
    a:as :: [a]
    as) = Int -> a -> Builder
    forall a. TextShow a => Int -> a -> Builder
    showbPrec 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 :: [a] -> Builder
    showbTuple args :: [a]
    args = Char -> Builder
    singleton '(' Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Builder -> [a] -> Builder
    forall a. TextShow a => Builder -> [a] -> Builder
    showbArgs (Char -> Builder
    singleton ',') [a]
    args Builder -> Builder -> Builder
    forall a. Semigroup a => a -> a -> a
    <> Char -> Builder
    singleton ')'
    {-# INLINE showbTuple #-}