Created
February 26, 2019 12:55
-
-
Save erichonorez/8fae2c994c15bbe008aa3fafbcd5b28e to your computer and use it in GitHub Desktop.
UseCase with Function1
This file contains 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
import cats.implicits._ | |
trait UseCase[In, Out, Err] extends Function1[In, Either[Err, Out]] | |
trait CreateLoanApplication extends UseCase[CreateLoanApplicationIn, CreateLoanApplicationOut, CreateLoanApplicationErr] { | |
override def apply(in: CreateLoanApplicationIn): Either[CreateLoanApplicationErr, CreateLoanApplicationOut] = { | |
Either.right(CreateLoanApplicationOut()) | |
} | |
} | |
case class CreateLoanApplicationIn() | |
case class CreateLoanApplicationOut() | |
sealed trait CreateLoanApplicationErr | |
case class DbErr() extends CreateLoanApplicationErr | |
case class ExternalErr() extends CreateLoanApplicationErr | |
object CreateLoanApplication extends CreateLoanApplication | |
trait CompletePersonalInformation extends UseCase[CompletePersonalInformationIn, CompletePersonalInformationOut, CompletePersonalInformationErr] { | |
override def apply(in: CompletePersonalInformationIn): Either[CompletePersonalInformationErr, CompletePersonalInformationOut] = { | |
Either.right(CompletePersonalInformationOut()) | |
} | |
} | |
case class CompletePersonalInformationIn() | |
case class CompletePersonalInformationOut() | |
sealed trait CompletePersonalInformationErr | |
case class DbError() extends CompletePersonalInformationErr | |
object CompletePersonalInformation extends CompletePersonalInformation | |
val main = for { | |
_ <- CreateLoanApplication(CreateLoanApplicationIn()) | |
_ <- CompletePersonalInformation(CompletePersonalInformationIn()) | |
} yield () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment