Skip to content

Instantly share code, notes, and snippets.

@monkey-codes
Created June 9, 2023 23:28
Show Gist options
  • Select an option

  • Save monkey-codes/a6f63ad1eddd394992ac686d50151139 to your computer and use it in GitHub Desktop.

Select an option

Save monkey-codes/a6f63ad1eddd394992ac686d50151139 to your computer and use it in GitHub Desktop.
Input IO monad
object Input {
...
private fun handle(programState: ProgramState, input: String): ProgramState = either {
...
val newState =
when (currentState) {
is InProgress -> {
val move =
Move.parse(input)
.mapLeft(errorToCurrentState)
.bind()
currentState.make(move).mapLeft(errorToCurrentState).bind()
}
else -> currentState
}
newState
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment