Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created April 8, 2018 03:42
Show Gist options
  • Save brianhsu/c1bfa50403d706bc57e65891855ca726 to your computer and use it in GitHub Desktop.
Save brianhsu/c1bfa50403d706bc57e65891855ca726 to your computer and use it in GitHub Desktop.
object UseCaseExecutor {
type Presenter[T] = (Try[T] => Unit)
}
abstract class UseCaseExecutor {
import UseCaseExecutor.Presenter
def execute[T](useCase: UseCase[T])(presenter: Presenter[T]): Unit = {
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