Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Projection state event = Projection {
- projectionSeed :: state
- projectionEventHandler :: state -> event -> state
- latestProjection :: Foldable t => Projection state event -> t event -> state
- allProjections :: Projection state event -> [event] -> [state]
- data StreamProjection key position state event = StreamProjection {
- streamProjectionKey :: !key
- streamProjectionPosition :: !position
- streamProjectionProjection :: !(Projection state event)
- streamProjectionState :: !state
- type VersionedStreamProjection = StreamProjection UUID EventVersion
- type GlobalStreamProjection state event = StreamProjection () SequenceNumber state (VersionedStreamEvent event)
- streamProjection :: key -> position -> Projection state event -> StreamProjection key position state event
- versionedStreamProjection :: UUID -> Projection state event -> VersionedStreamProjection state event
- globalStreamProjection :: Projection state (VersionedStreamEvent event) -> GlobalStreamProjection state event
- getLatestStreamProjection :: (Monad m, Num position) => EventStoreReader key position m (StreamEvent key position event) -> StreamProjection key position state event -> m (StreamProjection key position state event)
- serializedProjection :: Projection state event -> Serializer event serialized -> Projection state serialized
- projectionMapMaybe :: (eventB -> Maybe eventA) -> Projection state eventA -> Projection state eventB
Documentation
data Projection state event Source #
A Projection
is a piece of state
that is constructed only from
event
s. A Projection is how you reconstruct event sourced state from the
ordered stream of events that constitute that state. The "seed" of a
Projection is the initial state before any events are applied. The event
handler for a projection is the function that actually modifies state based
on the given event.
Projection | |
|
Contravariant (Projection state) Source # | |
latestProjection :: Foldable t => Projection state event -> t event -> state Source #
Computes the latest state of a Projection
from some events.
allProjections :: Projection state event -> [event] -> [state] Source #
Given a list of events, produce all the Projections that were ever
produced. Just a scanl
using projectionEventHandler
. This function is
useful for testing Projection
s; you can easily assert that all the states
of a Projection are valid given a list of events.
data StreamProjection key position state event Source #
A StreamProjection
is a Projection
that has been constructed from
events from a particular event stream. This is useful when we want to cache
the resulting state and also keep track of what part of the stream the state
is caught up to.
StreamProjection | |
|
type GlobalStreamProjection state event = StreamProjection () SequenceNumber state (VersionedStreamEvent event) Source #
streamProjection :: key -> position -> Projection state event -> StreamProjection key position state event Source #
Initialize a StreamProjection
with a Projection
, key, and order key.
versionedStreamProjection :: UUID -> Projection state event -> VersionedStreamProjection state event Source #
Initialize a VersionedStreamProjection
.
globalStreamProjection :: Projection state (VersionedStreamEvent event) -> GlobalStreamProjection state event Source #
Initialize a GlobalStreamProjection
.
getLatestStreamProjection :: (Monad m, Num position) => EventStoreReader key position m (StreamEvent key position event) -> StreamProjection key position state event -> m (StreamProjection key position state event) Source #
Gets the latest projection from a store by querying events from the latest order key and then applying the events using the Projection's event handler.
serializedProjection :: Projection state event -> Serializer event serialized -> Projection state serialized Source #
Use a Serializer
to wrap a Projection
with event type event
so it
uses the serialized
type.
projectionMapMaybe :: (eventB -> Maybe eventA) -> Projection state eventA -> Projection state eventB Source #
Transform a Projection
when you only have a partial relationship between
the source event type and the target event type.