Last active
April 7, 2020 07:20
-
-
Save ikovalyov/f9a1cc05780f9097b4725322eef0c405 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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