Last active
March 31, 2021 22:09
-
-
Save debasishg/7ff771bb695c2a330ccb to your computer and use it in GitHub Desktop.
Sample scala code with type constraints and kleisli composition
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 net.debasishg.fin | |
import org.joda.time.DateTime | |
trait Account { | |
def no: String | |
def name: String | |
def openedOn: DateTime | |
def closedOn: Option[DateTime] | |
} | |
case class CheckingAccount( | |
no: String, | |
name: String, | |
openedOn: DateTime, | |
closedOn: Option[DateTime]) extends Account | |
case class SavingsAccount( | |
no: String, | |
name: String, | |
openedOn: DateTime, | |
rateOfInterest: BigDecimal, | |
minBalance: BigDecimal, | |
closedOn: Option[DateTime]) extends Account | |
case class LoanAccount( | |
no: String, | |
name: String, | |
openedOn: DateTime, | |
rateOfInterest: Option[BigDecimal], | |
emi: Option[BigDecimal], | |
status: AccountStatus = Applied, | |
closedOn: Option[DateTime]) extends Account | |
sealed trait AccountStatus | |
case object Applied extends AccountStatus | |
case object Approved extends AccountStatus | |
case class Credentials(name: String, address: String, age: Int) | |
import scalaz._ | |
import Scalaz._ | |
trait LoanProcessing { | |
def applyForLoan[A <: LoanAccount](name: String, dateOfApplication: DateTime): Kleisli[Option, Credentials, A] | |
def approve[A <: LoanAccount](zone: String): Kleisli[Option, A, A] | |
def finalizeEMI[A <: LoanAccount](tenure: Int): Kleisli[Option, A, A] | |
def loanProcessing(name: String, dateOfApplication: DateTime, zone: String, tenure: Int) = | |
applyForLoan(name, dateOfApplication) >=> approve[LoanAccount](zone) >=> finalizeEMI(tenure) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment