diff --git a/core/src/lu/foyer/EventSourcing.scala b/core/src/lu/foyer/EventSourcing.scala index bd157af..370a4bf 100644 --- a/core/src/lu/foyer/EventSourcing.scala +++ b/core/src/lu/foyer/EventSourcing.scala @@ -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)) diff --git a/core/src/lu/foyer/Reducer.scala b/core/src/lu/foyer/Reducer.scala new file mode 100644 index 0000000..6d567fd --- /dev/null +++ b/core/src/lu/foyer/Reducer.scala @@ -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))