module Text.Show.Text.Data.Containers (
showbIntMapPrec
, showbIntSetPrec
, showbMapPrec
, showbSequencePrec
, showbSetPrec
, showbTreePrec
) where
import qualified Data.Foldable as F
import Data.Text.Lazy.Builder (Builder)
import qualified Data.IntMap as IM
import Data.IntMap (IntMap)
import qualified Data.IntSet as IS
import Data.IntSet (IntSet)
import qualified Data.Map as M
import Data.Map (Map)
import Data.Sequence (Seq)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.Tree (Tree)
import GHC.Show (appPrec)
import Prelude hiding (Show)
import Text.Show.Text.Class (Show(showb, showbPrec), showbParen)
import Text.Show.Text.Data.Integral ()
import Text.Show.Text.Data.List ()
import Text.Show.Text.Data.Tuple ()
import Text.Show.Text.TH.Internal (deriveShow)
import Text.Show.Text.Utils ((<>))
showbIntMapPrec :: Show v => Int -> IntMap v -> Builder
showbIntMapPrec p im
= showbParen (p > appPrec) $ "fromList " <> showb (IM.toList im)
showbIntSetPrec :: Int -> IntSet -> Builder
showbIntSetPrec p is
= showbParen (p > appPrec) $ "fromList " <> showb (IS.toList is)
showbMapPrec :: (Show k, Show v) => Int -> Map k v -> Builder
showbMapPrec p m
= showbParen (p > appPrec) $ "fromList " <> showb (M.toList m)
showbSequencePrec :: Show a => Int -> Seq a -> Builder
showbSequencePrec p s'
= showbParen (p > appPrec) $ "fromList " <> showb (F.toList s')
showbSetPrec :: Show a => Int -> Set a -> Builder
showbSetPrec p s'
= showbParen (p > appPrec) $ "fromList " <> showb (Set.toList s')
showbTreePrec :: Show a => Int -> Tree a -> Builder
showbTreePrec = showbPrec
instance Show v => Show (IntMap v) where
showbPrec = showbIntMapPrec
instance Show IntSet where
showbPrec = showbIntSetPrec
instance (Show k, Show v) => Show (Map k v) where
showbPrec = showbMapPrec
instance Show a => Show (Seq a) where
showbPrec = showbSequencePrec
instance Show a => Show (Set a) where
showbPrec = showbSetPrec
$(deriveShow ''Tree)