Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created September 27, 2020 15:07
Show Gist options
  • Save le0nidas/941b8ef8d83c4c0160d6e3a7826015c9 to your computer and use it in GitHub Desktop.
Save le0nidas/941b8ef8d83c4c0160d6e3a7826015c9 to your computer and use it in GitHub Desktop.
fun main() {
val executor = createActionExecutor()
executor.executeByResponse(Response("print", "leonidas"))
executor.executeByResponse(Response("log", "kotlin"))
executor.executeByResponse(Response("write_to_file", "leonidas loves kotlin"))
executor.executeByResponse(Response("print", "$&#$@#", isError = true))
}
private fun createActionExecutor(): ActionExecutor {
val printInErrorStream = PrintInErrorStream().asChain { response -> response.isError }
val justPrint = Print().asChain { true }
return ActionExecutor().apply {
addAction(printInErrorStream.or(justPrint))
addAction(Log())
addAction(WriteToFile())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment