You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently a query is a fold over all domain events in an eventstore which may result into some boiler plate code. For example, two queries for different events result into two folds which only differ in the actual type of the event.
val registeredUsers: (List<DomainEvent>) ->List<UserRegistered> = { it.fold(emptyList(),
{ s,d ->when(d){ isUserRegistered-> s + d else-> s }}
)}
val loggedInUsers: (List<DomainEvent>) ->List<UserLoggedIn> = { it.fold(emptyList(),
{s, d ->when(d){ isUserLoggedIn-> s + d else-> s}}
)}
Another problem occurs when we want to compose queries. For example, if we want to get all users which are currently viewing a specific page, we need to first query for all logged in users and then filter those which are on the page. However, composing those queries is quite hard with fold.
A little projection algebra
Let's think about query again. Instead using the fold model we can see it as a function.
A projection is a function from a list of events to a structure.
typealiasProjection<T> = (List<DomainEvent>) ->T
An empty projection does not project anything
val empty:Projection<List<DomainEvent>> = { it } // identity function
The text was updated successfully, but these errors were encountered:
Problem
Currently a query is a fold over all domain events in an eventstore which may result into some boiler plate code. For example, two queries for different events result into two folds which only differ in the actual type of the event.
Another problem occurs when we want to compose queries. For example, if we want to get all users which are currently viewing a specific page, we need to first query for all logged in users and then filter those which are on the page. However, composing those queries is quite hard with
fold
.A little projection algebra
Let's think about query again. Instead using the
fold
model we can see it as a function.The text was updated successfully, but these errors were encountered: