{-# LANGUAGE OverloadedStrings #-}

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

Miscellaneous utility functions.
-}
module TextShow.Utils (liftShowbUnaryWith, showbUnaryListWith) where

import TextShow (Builder, TextShow1(..), showbUnaryWith)

-- | This pattern is used frequently when showing transformer types.
liftShowbUnaryWith :: TextShow1 m
                   => (Int -> a -> Builder) -> ([a] -> Builder)
                   -> Builder -> Int -> m a -> Builder
liftShowbUnaryWith :: forall (m :: * -> *) a.
TextShow1 m =>
(Int -> a -> Builder)
-> ([a] -> Builder) -> Builder -> Int -> m a -> Builder
liftShowbUnaryWith Int -> a -> Builder
sp [a] -> Builder
sl = forall a. (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
showbUnaryWith (forall (f :: * -> *) a.
TextShow1 f =>
(Int -> a -> Builder) -> ([a] -> Builder) -> Int -> f a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
sl)
{-# INLINE liftShowbUnaryWith #-}

-- | This pattern is used frequently when showing container types.
showbUnaryListWith :: ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith :: forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith [a] -> Builder
sl Int
p = forall a. (Int -> a -> Builder) -> Builder -> Int -> a -> Builder
showbUnaryWith (forall a b. a -> b -> a
const [a] -> Builder
sl) Builder
"fromList" Int
p
{-# INLINE showbUnaryListWith #-}