{-# OPTIONS_GHC -Wno-orphans #-}
{-|
Module:      TextShow.Data.UnorderedContainers
Copyright:   (C) 2014-2017 Ryan Scott
License:     BSD-style (see the file LICENSE)
Maintainer:  Ryan Scott
Stability:   Provisional
Portability: GHC

'TextShow' instances for 'HashMap' and 'HashSet'.

/Since: 2/
-}
module TextShow.Data.UnorderedContainers () where

import qualified Data.HashMap.Lazy as HM (toList)
import           Data.HashMap.Lazy (HashMap)
import qualified Data.HashSet as HS (toList)
import           Data.HashSet (HashSet)

import           TextShow (TextShow(..), TextShow1(..), TextShow2(..), showbPrec1)
import           TextShow.Utils (showbUnaryListWith)

-- | /Since: 2/
instance (TextShow k, TextShow v) => TextShow (HashMap k v) where
    showbPrec :: Int -> HashMap k v -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow k => TextShow1 (HashMap k) where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> HashMap 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 #-}

-- | /Since: 2/
instance TextShow2 HashMap where
    liftShowbPrec2 :: forall a b.
(Int -> a -> Builder)
-> ([a] -> Builder)
-> (Int -> b -> Builder)
-> ([b] -> Builder)
-> Int
-> HashMap 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 v. HashMap k v -> [(k, v)]
HM.toList
    {-# INLINE liftShowbPrec2 #-}

-- | /Since: 2/
instance TextShow a => TextShow (HashSet a) where
    showbPrec :: Int -> HashSet a -> Builder
showbPrec = forall (f :: * -> *) a.
(TextShow1 f, TextShow a) =>
Int -> f a -> Builder
showbPrec1
    {-# INLINE showbPrec #-}

-- | /Since: 2/
instance TextShow1 HashSet where
    liftShowbPrec :: forall a.
(Int -> a -> Builder)
-> ([a] -> Builder) -> Int -> HashSet 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. HashSet a -> [a]
HS.toList
    {-# INLINE liftShowbPrec #-}