Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created April 8, 2018 01:07
Show Gist options
  • Save brianhsu/56edbbbeb821f1c0146f99a45916f99f to your computer and use it in GitHub Desktop.
Save brianhsu/56edbbbeb821f1c0146f99a45916f99f to your computer and use it in GitHub Desktop.
package moe.brianhsu.gtd.usecase
import moe.brianhsu.gtd.journal.Journal
import scala.util._
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