-- |
-- Module      :  Games.ECS.Util.Misc
-- Description : Other junk.
-- Copyright   :  (C) 2020 Sophie Taylor
-- License     :  AGPL-3.0-or-later
-- Maintainer  :  Sophie Taylor <sophie@spacekitteh.moe>
-- Stability   :  experimental
-- Portability: GHC
--
-- Things which don't really fit anywhere else.

module Games.ECS.Util.Misc where

import Data.Hashable
import Data.Sequence (Seq)

-- | a 'Hashable' 'Seq'.
newtype HashableSeq a = HashableSeq (Seq a) deriving newtype HashableSeq a -> HashableSeq a -> Bool
(HashableSeq a -> HashableSeq a -> Bool)
-> (HashableSeq a -> HashableSeq a -> Bool) -> Eq (HashableSeq a)
forall a. Eq a => HashableSeq a -> HashableSeq a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => HashableSeq a -> HashableSeq a -> Bool
== :: HashableSeq a -> HashableSeq a -> Bool
$c/= :: forall a. Eq a => HashableSeq a -> HashableSeq a -> Bool
/= :: HashableSeq a -> HashableSeq a -> Bool
Eq

instance Hashable a => Hashable (HashableSeq a) where
  {-# INLINE hashWithSalt #-}
  hashWithSalt :: Int -> HashableSeq a -> Int
hashWithSalt Int
salt (HashableSeq Seq a
s) = (Int -> a -> Int) -> Int -> Seq a -> Int
forall b a. (b -> a -> b) -> b -> Seq a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Int -> a -> Int
forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt Seq a
s