Created
April 8, 2018 03:12
-
-
Save brianhsu/a2dba255d6a5e8d5a82605af71f842a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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