mirror of
https://github.com/facebook/Haxl.git
synced 2025-01-08 19:00:25 +03:00
Add Monoid instance for StateStore
Summary: Add a monoid instance for merging two StateStores. Reviewed By: watashi Differential Revision: D8961041 fbshipit-source-id: f6539ec0f0915b572a42ab34c098a9be6c8664f1
This commit is contained in:
parent
aba36943e5
commit
2f8204cc2a
@ -24,6 +24,7 @@ module Haxl.Core.StateStore
|
||||
|
||||
import Data.Map (Map)
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Data.Monoid
|
||||
import Data.Typeable
|
||||
import Unsafe.Coerce
|
||||
|
||||
@ -47,6 +48,11 @@ class Typeable1 f => StateKey (f :: * -> *) where
|
||||
-- | The 'StateStore' maps a 'StateKey' to the 'State' for that type.
|
||||
newtype StateStore = StateStore (Map TypeRep StateStoreData)
|
||||
|
||||
instance Monoid StateStore where
|
||||
mempty = stateEmpty
|
||||
-- Left-biased union
|
||||
mappend (StateStore m1) (StateStore m2) = StateStore $ m1 <> m2
|
||||
|
||||
-- | Encapsulates the type of 'StateStore' data so we can have a
|
||||
-- heterogeneous collection.
|
||||
data StateStoreData = forall f. StateKey f => StateStoreData (State f)
|
||||
|
Loading…
Reference in New Issue
Block a user