{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS -Wno-orphans #-}
module TextShow.Data.Containers () where
import qualified Data.Foldable as F
import Data.Graph (SCC)
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(..), showbPrec1)
import TextShow.Data.Integral ()
import TextShow.TH (deriveTextShow, deriveTextShow1)
import TextShow.Utils (showbUnaryListWith)
instance TextShow v => TextShow (IntMap v) where
showbPrec :: Int -> IntMap v -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
{-# INLINE showbPrec #-}
instance TextShow1 IntMap where
liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> IntMap a -> Builder
liftShowbPrec Int -> a -> Builder
sp [a] -> Builder
_ Int
p =
forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith (forall (f :: * -> * -> *) a b.
TextShow2 f =>
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> [f a b]
-> Builder
liftShowbList2 forall a. TextShow a => Int -> a -> Builder
showbPrec forall a. HasCallStack => a
undefined
(forall a b. a -> b -> a
const (Int -> a -> Builder
sp Int
0)) forall a. HasCallStack => a
undefined) Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IntMap a -> [(Int, a)]
IM.toList
{-# INLINE liftShowbPrec #-}
instance TextShow IntSet where
showbPrec :: Int -> IntSet -> Builder
showbPrec Int
p = forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith forall a. TextShow a => [a] -> Builder
showbList Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
IS.toList
{-# INLINE showbPrec #-}
instance (TextShow k, TextShow v) => TextShow (Map k v) where
showbPrec :: Int -> Map k v -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
{-# INLINE showbPrec #-}
instance TextShow k => TextShow1 (Map k) where
liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Map k a -> Builder
liftShowbPrec = forall (f :: * -> * -> *) a b.
TextShow2 f =>
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> Int
-> f a b
-> Builder
liftShowbPrec2 forall a. TextShow a => Int -> a -> Builder
showbPrec forall a. TextShow a => [a] -> Builder
showbList
{-# INLINE liftShowbPrec #-}
instance TextShow2 Map where
liftShowbPrec2 :: forall a b.
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> Int
-> Map a b
-> Builder
liftShowbPrec2 Int -> a -> Builder
sp1 [a] -> Builder
_ Int -> b -> Builder
sp2 [b] -> Builder
_ Int
p =
forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith (forall (f :: * -> * -> *) a b.
TextShow2 f =>
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> [f a b]
-> Builder
liftShowbList2 (forall a b. a -> b -> a
const (Int -> a -> Builder
sp1 Int
0)) forall a. HasCallStack => a
undefined
(forall a b. a -> b -> a
const (Int -> b -> Builder
sp2 Int
0)) forall a. HasCallStack => a
undefined) Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Map k a -> [(k, a)]
M.toList
{-# INLINE liftShowbPrec2 #-}
instance TextShow a => TextShow (Seq a) where
showbPrec :: Int -> Seq a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
{-# INLINE showbPrec #-}
instance TextShow1 Seq where
liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Seq a -> Builder
liftShowbPrec Int -> a -> Builder
_ [a] -> Builder
sl Int
p = forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith [a] -> Builder
sl Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList
{-# INLINE liftShowbPrec #-}
$(deriveTextShow ''ViewL)
$(deriveTextShow1 ''ViewL)
$(deriveTextShow ''ViewR)
$(deriveTextShow1 ''ViewR)
instance TextShow a => TextShow (Set a) where
showbPrec :: Int -> Set a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
{-# INLINE showbPrec #-}
instance TextShow1 Set where
liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> Set a -> Builder
liftShowbPrec Int -> a -> Builder
_ [a] -> Builder
sl Int
p = forall a. ([a] -> Builder) -> Int -> [a] -> Builder
showbUnaryListWith [a] -> Builder
sl Int
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Set a -> [a]
Set.toList
{-# INLINE liftShowbPrec #-}
$(deriveTextShow ''SCC)
$(deriveTextShow1 ''SCC)
$(deriveTextShow ''Tree)
$(deriveTextShow1 ''Tree)