This PR changes the type signature of state functions in FSMs to curry the state manager. This makes the syntax a bit cleaner, especially for multiple cases of events, and slighly closer to Akka (which doesn't need a state manager argument).
Made up example:
object Before {
// Partial function gives the impression the state manager is also changing and something to match against!
type StateFunction =
PartialFunction[(FSM.Event[Any, Request], StateManager[IO, SomeState, Any, Request, Any]), IO[
State[SomeState, Any, Request, Any]
]]
def someStateFunction: StateFunction = {
case (FSM.Event(Start, _), stateManager) =>
stateManager.goto(Active)
case (FSM.Event(Stop, _), stateManager) => // we have to repeat the stateManager in each case!
stateManager.stay()
}
}
object After {
type StateFunction = StateManager[IO, SomeState, Any, Request, Any] =>
PartialFunction[FSM.Event[Any, Request], IO[
State[SomeState, Any, Request, Any]
]]
def someStateFunction: StateFunction = stateManager => {
case FSM.Event(Start, _) =>
stateManager.goto(Active)
case FSM.Event(Stop, _) =>
stateManager.stay()
}
}
This PR changes the type signature of state functions in FSMs to curry the state manager. This makes the syntax a bit cleaner, especially for multiple cases of events, and slighly closer to Akka (which doesn't need a state manager argument).
Made up example: