Skip to content

Instantly share code, notes, and snippets.

@ikovalyov
Last active April 7, 2020 07:20
Show Gist options
  • Save ikovalyov/f9a1cc05780f9097b4725322eef0c405 to your computer and use it in GitHub Desktop.
Save ikovalyov/f9a1cc05780f9097b4725322eef0c405 to your computer and use it in GitHub Desktop.
abstract class Transition<InputState: State, OutputState: State> {
abstract fun invoke(state: InputState) : OutputState
}
class ValidateRequest: Transition<State.RequestReceived, State.RequestValidated>() {
override fun invoke(state: State.RequestReceived): State.RequestValidated {
// let's just check something here
return State.RequestValidated(state.request > 0, state)
}
}
class ProcessRequest: Transition<State.RequestValidated, State.RequestProcessed>() {
override fun invoke(state: State.RequestValidated): State.RequestProcessed {
return State.RequestProcessed(state.previousState.request * 2, state)
}
}
class ValidateResponse: Transition<State.RequestProcessed, State.ResponseValidated>() {
override fun invoke(state: State.RequestProcessed): State.ResponseValidated {
// let's just check something here
return State.ResponseValidated(state.response > 0, state)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment