-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | In-memory implementations for eventful
--   
--   In-memory implementations for eventful
@package eventful-memory
@version 0.2.0

module Eventful.ProjectionCache.Memory

-- | A <a>ProjectionMap</a> just stores the latest snapshot for each UUID.
type ProjectionMap key position serialized = Map key (position, serialized)
emptyProjectionMap :: ProjectionMap key position serialized
projectionMapTVar :: IO (TVar (ProjectionMap key position serialized))

-- | A <a>ProjectionCache</a> that uses a <a>TVar</a> and runs in
--   <a>STM</a>.
tvarProjectionCache :: (Ord key) => TVar (ProjectionMap key position serialized) -> ProjectionCache key position serialized STM

-- | A <a>ProjectionCache</a> for some <a>MonadState</a> that contains a
--   <a>ProjectionMap</a>.
embeddedStateProjectionCache :: (MonadState s m, Ord key) => (s -> ProjectionMap key position serialized) -> (s -> ProjectionMap key position serialized -> s) -> ProjectionCache key position serialized m

module Eventful.ReadModel.Memory

-- | Creates a read model that wraps some pure data in a TVar and manages
--   the latest sequence number for you.
memoryReadModel :: (MonadIO m) => modeldata -> (modeldata -> [GlobalStreamEvent serialized] -> m modeldata) -> IO (ReadModel (TVar (MemoryReadModelData modeldata)) serialized m)
instance GHC.Show.Show modeldata => GHC.Show.Show (Eventful.ReadModel.Memory.MemoryReadModelData modeldata)

module Eventful.Store.Memory

-- | An <a>EventStoreReader</a> that stores events in a <a>TVar</a> and
--   runs in <a>STM</a>. This functions initializes the store by creating
--   the <a>TVar</a> and hooking up the event store API to that
--   <a>TVar</a>.
tvarEventStoreReader :: TVar (EventMap event) -> VersionedEventStoreReader STM event
tvarEventStoreWriter :: TVar (EventMap event) -> EventStoreWriter STM event

-- | Analog of <a>tvarEventStoreReader</a> for a
--   <a>GlobalEventStoreReader</a>
tvarGlobalEventStoreReader :: TVar (EventMap event) -> GlobalEventStoreReader STM event

-- | Specialized version of <a>embeddedStateEventStoreReader</a> that only
--   contains an <a>EventMap</a> in the state.
stateEventStoreReader :: (MonadState (EventMap event) m) => VersionedEventStoreReader m event

-- | Specialized version of <a>embeddedStateEventStoreWriter</a> that only
--   contains an <a>EventMap</a> in the state.
stateEventStoreWriter :: (MonadState (EventMap event) m) => EventStoreWriter m event
stateGlobalEventStoreReader :: (MonadState (EventMap event) m) => GlobalEventStoreReader m event

-- | An <tt>EventStore</tt> that runs on some <a>MonadState</a> that
--   contains an <a>EventMap</a>. This is useful if you want to include
--   other state in your <a>MonadState</a>.
embeddedStateEventStoreReader :: (MonadState s m) => (s -> EventMap event) -> VersionedEventStoreReader m event
embeddedStateEventStoreWriter :: (MonadState s m) => (s -> EventMap event) -> (s -> EventMap event -> s) -> EventStoreWriter m event

-- | Analogous to <tt>embeddedStateEventStore</tt> for a
--   <tt>GlobalStreamEventStore</tt>.
embeddedStateGlobalEventStoreReader :: (MonadState s m) => (s -> EventMap event) -> GlobalEventStoreReader m event

-- | Internal data structure used for the in-memory event stores.
data EventMap event

-- | What it says on the tin, an initialized empty <a>EventMap</a>
emptyEventMap :: EventMap event

-- | Initialize an <a>EventMap</a> in a <a>TVar</a>
eventMapTVar :: IO (TVar (EventMap event))
instance GHC.Show.Show event => GHC.Show.Show (Eventful.Store.Memory.EventMap event)
