juan_gandhi: (VP)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2014-03-01 02:46 pm
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
    }
  }


[identity profile] http://users.livejournal.com/_xacid_/ 2014-03-02 12:37 am (UTC)(link)
хочу сделать чтото подобное но пока не собрал в кучку мысли