Skip to content

Instantly share code, notes, and snippets.

@ikovalyov
Created March 31, 2020 22:39
Show Gist options
  • Save ikovalyov/974d386413a9deb4b7b3982684ff93ee to your computer and use it in GitHub Desktop.
Save ikovalyov/974d386413a9deb4b7b3982684ff93ee to your computer and use it in GitHub Desktop.
fun List<Transition<State, State>>.fold(initial: State.RequestReceived): State.ResponseValidated {
var currentState: State = initial
forEach {
currentState = it.invoke(currentState)
}
if (currentState is State.ResponseValidated) {
return currentState as State.ResponseValidated
} else {
throw IllegalStateException("currentState is not of State.ResponseValidated type")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment