Created
April 8, 2018 01:07
-
-
Save brianhsu/56edbbbeb821f1c0146f99a45916f99f 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
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