Juan-Carlos Gandhi (
juan_gandhi) wrote2014-03-01 02:46 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Entry tags:
code sample - before and after
(scala below)
Before
def buildItem(eob:EOB)(props: Props): Result[EOB_item] = { implicit val empty: String = "" // weird for (sDate <- props valueOf DateOfServicePerItem; date <- DateFormat("MM/dd/yyyy").parseCurrent(sDate); description <- props valueOf ProcedureDescription; sBilled <- props valueOf BilledPerItem; billed <- dollars(sBilled); sInsPaid <- props valueOf PaidByPlanPerItem; insPaid <- dollars(sInsPaid); sDeductible <- props valueOf Deductible; deductible <- dollars(sDeductible); sCoinsurance <- props valueOf Coinsurance; deductible <- dollars(sDeductible); sCopay <- props valueOf CopayPerItem; copay <- dollars(sDeductible); sAllowed <- props valueOf Allowed; allowed <- dollars(sDeductible); x <- Good(true)) yield new EOB_item() {//...
after
val ex = new DataExtractor(props, DateFormat("MM/dd/yyyy").parseCurrent) implicit def extractor(name: String) = ex(name) for (date <- DateOfServicePerItem asRecentDate; description <- ProcedureDescription requireText; billed <- BilledPerItem $$$; insPaid <- PaidByPlanPerItem $$$; deductible <- Deductible $$$; coinsurance <- Coinsurance $$$; copay <- CopayPerItem $$$; allowed <- Allowed $$$; x <- Good(true)) yield new EOB_item() {
where
class DataExtractor(props:Props, string2date: String=>Result[Date]) { def apply(name:String) = new { def requireText: Result[String] = props valueOf name def text:String = requireText getOrElse "" def $$$: Result[BigDecimalField] = requireText flatMap dollars def asRecentDate = requireText flatMap string2date } }
no subject
no subject