handle

abstract fun handle(currentState: T, event: E): T

Handles the given event in the context of the current state.

This method should be pure and deterministic - given the same current state and event, it should always produce the same result.

Side effects should be handled separately from state transitions.

Return

The new state after handling the event

Parameters

currentState

The current state before the event

event

The event to handle

Throws

if the event cannot be handled or processing fails