Created
March 31, 2020 22:39
-
-
Save ikovalyov/974d386413a9deb4b7b3982684ff93ee 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
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