{-# OPTIONS_GHC -Wno-orphans #-}

-- |
-- Module      : Streamly.Internal.Data.IsMap.HashMap
-- Copyright   : (c) 2022 Composewell Technologies
-- License     : BSD-3-Clause
-- Maintainer  : streamly@composewell.com
-- Stability   : experimental
-- Portability : GHC
--
-- Adds an orphan HashMap instance for the IsMap type class from streamly-core
-- package. This is useful for various combinators that use a map type. We
-- cannot define this in streamly-core as it adds several non-boot library
-- dependencies on streamly-core.

module Streamly.Internal.Data.IsMap.HashMap () where

import Data.Hashable (Hashable)
import Streamly.Internal.Data.IsMap (IsMap(..))

import qualified Data.HashMap.Strict as HashMap

#if MIN_VERSION_hashable(1,4,0)
instance (Hashable k) => IsMap (HashMap.HashMap k) where
#else
instance (Hashable k, Eq k) => IsMap (HashMap.HashMap k) where
#endif
    type Key (HashMap.HashMap k) = k

    mapEmpty :: forall a. HashMap k a
mapEmpty = HashMap k a
forall k v. HashMap k v
HashMap.empty
    mapAlterF :: forall (g :: * -> *) a.
Functor g =>
(Maybe a -> g (Maybe a))
-> Key (HashMap k) -> HashMap k a -> g (HashMap k a)
mapAlterF = (Maybe a -> g (Maybe a)) -> k -> HashMap k a -> g (HashMap k a)
(Maybe a -> g (Maybe a))
-> Key (HashMap k) -> HashMap k a -> g (HashMap k a)
forall (f :: * -> *) k v.
(Functor f, Eq k, Hashable k) =>
(Maybe v -> f (Maybe v)) -> k -> HashMap k v -> f (HashMap k v)
HashMap.alterF
    mapLookup :: forall a. Key (HashMap k) -> HashMap k a -> Maybe a
mapLookup = k -> HashMap k a -> Maybe a
Key (HashMap k) -> HashMap k a -> Maybe a
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup
    mapInsert :: forall a. Key (HashMap k) -> a -> HashMap k a -> HashMap k a
mapInsert = k -> a -> HashMap k a -> HashMap k a
Key (HashMap k) -> a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
HashMap.insert
    mapDelete :: forall a. Key (HashMap k) -> HashMap k a -> HashMap k a
mapDelete = k -> HashMap k a -> HashMap k a
Key (HashMap k) -> HashMap k a -> HashMap k a
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
HashMap.delete
    mapUnion :: forall a. HashMap k a -> HashMap k a -> HashMap k a
mapUnion = HashMap k a -> HashMap k a -> HashMap k a
forall k v.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k v -> HashMap k v
HashMap.union
    mapNull :: forall a. HashMap k a -> Bool
mapNull = HashMap k a -> Bool
forall k v. HashMap k v -> Bool
HashMap.null
    mapTraverseWithKey :: forall (t :: * -> *) a b.
Applicative t =>
(Key (HashMap k) -> a -> t b) -> HashMap k a -> t (HashMap k b)
mapTraverseWithKey = (k -> a -> t b) -> HashMap k a -> t (HashMap k b)
(Key (HashMap k) -> a -> t b) -> HashMap k a -> t (HashMap k b)
forall (f :: * -> *) k v1 v2.
Applicative f =>
(k -> v1 -> f v2) -> HashMap k v1 -> f (HashMap k v2)
HashMap.traverseWithKey