Skip to content

Instantly share code, notes, and snippets.

@erichonorez
Created February 26, 2019 12:55
Show Gist options
  • Save erichonorez/8fae2c994c15bbe008aa3fafbcd5b28e to your computer and use it in GitHub Desktop.
Save erichonorez/8fae2c994c15bbe008aa3fafbcd5b28e to your computer and use it in GitHub Desktop.
UseCase with Function1
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