{-# LANGUAGE DerivingVia        #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}

module NoThunks.Class.Orphans where

import Data.IntPSQ (IntPSQ)
import Data.IntPSQ qualified as IntPSQ
import Data.OrdPSQ (OrdPSQ)
import Data.OrdPSQ qualified as OrdPSQ

import Network.Socket (SockAddr)

import NoThunks.Class

noThunksInKeysPrioritiesAndValues
  :: (NoThunks k, NoThunks v, NoThunks p)
  => Context -> [(k, v, p)] -> IO (Maybe ThunkInfo)
noThunksInKeysPrioritiesAndValues :: forall k v p.
(NoThunks k, NoThunks v, NoThunks p) =>
Context -> [(k, v, p)] -> IO (Maybe ThunkInfo)
noThunksInKeysPrioritiesAndValues Context
ctxt =
      [IO (Maybe ThunkInfo)] -> IO (Maybe ThunkInfo)
allNoThunks
    ([IO (Maybe ThunkInfo)] -> IO (Maybe ThunkInfo))
-> ([(k, v, p)] -> [IO (Maybe ThunkInfo)])
-> [(k, v, p)]
-> IO (Maybe ThunkInfo)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k, v, p) -> [IO (Maybe ThunkInfo)])
-> [(k, v, p)] -> [IO (Maybe ThunkInfo)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(k
k, v
v, p
p) -> [ Context -> k -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctxt k
k
                               , Context -> v -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctxt v
v
                               , Context -> p -> IO (Maybe ThunkInfo)
forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo)
noThunks Context
ctxt p
p
                               ])

instance (NoThunks p, NoThunks k, NoThunks v) => NoThunks (OrdPSQ k p v) where
    wNoThunks :: Context -> OrdPSQ k p v -> IO (Maybe ThunkInfo)
wNoThunks Context
ctxt OrdPSQ k p v
a = Context -> [(k, p, v)] -> IO (Maybe ThunkInfo)
forall k v p.
(NoThunks k, NoThunks v, NoThunks p) =>
Context -> [(k, v, p)] -> IO (Maybe ThunkInfo)
noThunksInKeysPrioritiesAndValues Context
ctxt (OrdPSQ k p v -> [(k, p, v)]
forall k p v. OrdPSQ k p v -> [(k, p, v)]
OrdPSQ.toList OrdPSQ k p v
a)
    showTypeOf :: Proxy (OrdPSQ k p v) -> String
showTypeOf Proxy (OrdPSQ k p v)
_ = String
"OrdPSQ"

instance (NoThunks k, NoThunks v) => NoThunks (IntPSQ k v) where
    wNoThunks :: Context -> IntPSQ k v -> IO (Maybe ThunkInfo)
wNoThunks Context
ctxt IntPSQ k v
a = Context -> [(Int, k, v)] -> IO (Maybe ThunkInfo)
forall k v p.
(NoThunks k, NoThunks v, NoThunks p) =>
Context -> [(k, v, p)] -> IO (Maybe ThunkInfo)
noThunksInKeysPrioritiesAndValues Context
ctxt ((\(Int
k, k
p, v
v) -> (Int
k, k
p, v
v)) ((Int, k, v) -> (Int, k, v)) -> [(Int, k, v)] -> [(Int, k, v)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IntPSQ k v -> [(Int, k, v)]
forall p v. IntPSQ p v -> [(Int, p, v)]
IntPSQ.toList IntPSQ k v
a)
    showTypeOf :: Proxy (IntPSQ k v) -> String
showTypeOf Proxy (IntPSQ k v)
_ = String
"IntPSQ"

deriving via InspectHeap SockAddr instance NoThunks SockAddr