我有一個關於下面的代碼部分的問題:Scala的含義:「C @請求」
sealed trait Claim { val claimId: Int }
case class Full(val claimId: Int) extends Claim
case class Partial(val claimId: Int, percentage: Double) extends Claim
case class Generic(override val claimId: Int) extends Claim
case class Location(stateCode: Option[String], zipCode: Option[String])
case class Req(productId: String, location: Location, claim: Claim)
object PricingSystem {
type PC = Tuple2[Req, Option[Double]]
def handleFullClaim: PartialFunction[PC, PC] = {
case ([email protected](id, l, Full(claimId)), basePrice) => (c, basePrice.map(_ + 10))
}
def handlePartialClaim: PartialFunction[PC, PC] = {
case ([email protected](id, l, Partial(claimId, percentage)), basePrice) => (c, basePrice.map(_ + 20))
}
def handleZipCode: PartialFunction[PC, PC] = {
case ([email protected](id, Location(_, Some(zipCode)), _), price) => (c, price.map(_ + 5))
}
def handleStateCode: PartialFunction[PC, PC] = {
case ([email protected](id, Location(Some(stateCode), _), _), price) => (c, price.map(_ + 10))
}
def claimHandlers = handleFullClaim orElse handlePartialClaim
def locationHandlers = handleZipCode orElse handleStateCode
def default: PartialFunction[PC, PC] = { case p => p }
def priceCalculator: PartialFunction[PC, PC] =
(claimHandlers andThen locationHandlers) orElse default
def main(args: Array[String]) = {
priceCalculator((Req("some product", Location(None, Some("43230")), Full(1)), Some(10))) match {
case (c, finalPrice) => println(finalPrice)
}
priceCalculator((Req("some product", Location(None, None), Generic(10)), Some(10))) match {
case (c, finalPrice) => println(finalPrice)
}
}
}
是什麼下面的代碼片段意味着階:[email protected]
?特別是:@
在這裏簽字是什麼意思?
看到這個確切的問題:http://stackoverflow.com/questions/20748858/pattern-matching-symbol/20748908#20748908 – wheaties