Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created April 8, 2018 03:12
Show Gist options
  • Save brianhsu/a2dba255d6a5e8d5a82605af71f842a1 to your computer and use it in GitHub Desktop.
Save brianhsu/a2dba255d6a5e8d5a82605af71f842a1 to your computer and use it in GitHub Desktop.
object UseCaseExecutor {
type Presenter[T, R] = (Try[T] => R)
}
abstract class UseCaseExecutor {
import UseCaseExecutor.Presenter
def execute[T, R](useCase: UseCase[T])(presenter: Presenter[T, R]): R = {
val result = Try {
useCase.validate().foreach { error => throw error }
val result = useCase.execute()
useCase.journal.foreach(appendJournal)
result
}
presenter(result)
}
def appendJournal(journal: Journal): Unit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment