Move reducer
This commit is contained in:
parent
4bd2a1518b
commit
46cb9e014e
2 changed files with 11 additions and 10 deletions
|
|
@ -12,13 +12,3 @@ trait StateRepository[Data] extends Repository[Entity[Data], String]
|
|||
trait EventRepository[Data] extends Repository[Event[Data], String]:
|
||||
def fetchOne(entityId: String, eventId: String): Task[Option[Event[Data]]]
|
||||
def fetchMany(entityId: String, page: Page): Task[Paged[Event[Data]]]
|
||||
|
||||
trait Reducer[Event, State]:
|
||||
def fromEmpty: PartialFunction[Event, State]
|
||||
def fromState: PartialFunction[(State, Event), State]
|
||||
|
||||
def reduce(event: Event): Option[State] =
|
||||
fromEmpty.lift(event)
|
||||
|
||||
def reduce(state: State, event: Event): Option[State] =
|
||||
fromState.lift((state, event))
|
||||
|
|
|
|||
11
core/src/lu/foyer/Reducer.scala
Normal file
11
core/src/lu/foyer/Reducer.scala
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package lu.foyer
|
||||
|
||||
trait Reducer[Event, State]:
|
||||
def fromEmpty: PartialFunction[Event, State]
|
||||
def fromState: PartialFunction[(State, Event), State]
|
||||
|
||||
def reduce(event: Event): Option[State] =
|
||||
fromEmpty.lift(event)
|
||||
|
||||
def reduce(state: State, event: Event): Option[State] =
|
||||
fromState.lift((state, event))
|
||||
Loading…
Add table
Add a link
Reference in a new issue