module TextShow.Data.Containers (
liftShowbIntMapPrec
, showbIntSetPrec
, liftShowbMapPrec2
, liftShowbSequencePrec
, liftShowbViewLPrec
, liftShowbViewRPrec
, liftShowbSetPrec
, liftShowbTreePrec
) where
import qualified Data.Foldable as F
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, ViewL, ViewR)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.Tree (Tree)
import TextShow (TextShow(..), TextShow1(..), TextShow2(..),
Builder, showbPrec1)
import TextShow.Data.Integral ()
import TextShow.TH (deriveTextShow, deriveTextShow1)
import TextShow.Utils (showbUnaryListWith)
#include "inline.h"
liftShowbIntMapPrec :: (v -> Builder) -> Int -> IntMap v -> Builder
liftShowbIntMapPrec sp p =
showbUnaryListWith (liftShowbList2 showbPrec undefined
(const sp) undefined) p . IM.toList
showbIntSetPrec :: Int -> IntSet -> Builder
showbIntSetPrec p = showbUnaryListWith showbList p . IS.toList
liftShowbMapPrec2 :: (k -> Builder) -> (v -> Builder) -> Int -> Map k v -> Builder
liftShowbMapPrec2 sp1 sp2 p =
showbUnaryListWith (liftShowbList2 (const sp1) undefined
(const sp2) undefined) p . M.toList
liftShowbSequencePrec :: ([a] -> Builder) -> Int -> Seq a -> Builder
liftShowbSequencePrec sl p = showbUnaryListWith sl p . F.toList
liftShowbViewLPrec :: (Int -> a -> Builder) -> ([a] -> Builder)
-> Int -> ViewL a -> Builder
liftShowbViewLPrec = liftShowbPrec
liftShowbViewRPrec :: (Int -> a -> Builder) -> ([a] -> Builder)
-> Int -> ViewR a -> Builder
liftShowbViewRPrec = liftShowbPrec
liftShowbSetPrec :: ([a] -> Builder) -> Int -> Set a -> Builder
liftShowbSetPrec sl p = showbUnaryListWith sl p . Set.toList
liftShowbTreePrec :: (Int -> a -> Builder) -> ([a] -> Builder)
-> Int -> Tree a -> Builder
liftShowbTreePrec = liftShowbPrec
instance TextShow v => TextShow (IntMap v) where
showbPrec = showbPrec1
INLINE_INST_FUN(showbPrec)
instance TextShow1 IntMap where
liftShowbPrec sp _ = liftShowbIntMapPrec (sp 0)
INLINE_INST_FUN(liftShowbPrec)
instance TextShow IntSet where
showbPrec = showbIntSetPrec
INLINE_INST_FUN(showbPrec)
instance (TextShow k, TextShow v) => TextShow (Map k v) where
showbPrec = showbPrec1
INLINE_INST_FUN(showbPrec)
instance TextShow k => TextShow1 (Map k) where
liftShowbPrec = liftShowbPrec2 showbPrec showbList
INLINE_INST_FUN(liftShowbPrec)
instance TextShow2 Map where
liftShowbPrec2 sp1 _ sp2 _ = liftShowbMapPrec2 (sp1 0) (sp2 0)
INLINE_INST_FUN(liftShowbPrec2)
instance TextShow a => TextShow (Seq a) where
showbPrec = showbPrec1
INLINE_INST_FUN(showbPrec)
instance TextShow1 Seq where
liftShowbPrec _ = liftShowbSequencePrec
INLINE_INST_FUN(liftShowbPrec)
$(deriveTextShow ''ViewL)
$(deriveTextShow1 ''ViewL)
$(deriveTextShow ''ViewR)
$(deriveTextShow1 ''ViewR)
instance TextShow a => TextShow (Set a) where
showbPrec = showbPrec1
INLINE_INST_FUN(showbPrec)
instance TextShow1 Set where
liftShowbPrec _ = liftShowbSetPrec
INLINE_INST_FUN(liftShowbPrec)
$(deriveTextShow ''Tree)
$(deriveTextShow1 ''Tree)