文档介绍:Scala 解决问题
1
精选PPT
目录
Why scala
用scala 解决问题
More about scala
Q &A
Polyglot programming
2
精选PPT
Polyglot programming
Java
Scala
Ruby
Python
Groovy
C++
……
3
精选PPT
Why scala
Productivity
Maintainability
extensibility
4
精选PPT
High order function
class FollowingRule() extends Rule with PricingService {
def apply(ev: Event):Pricing = {
val oppProducts: List[OppProduct] = getOppproducts()
val availabled = oppProducts filter { } //有货的
availabled match {
case List() => new AbnormalPricing(ev, "without opponent")
case _ => {
val lowPriced: OppProduct = () //最低价的
new SubmitPricing(ev, , "following " + lowPriced)
}
}
}
}
5
精选PPT
Function composition :1
object RuleFactory extends PricingService with Tracer{
abstract class Filter extends (Pricing => Pricing)
val following = new FollowingRule()
val markdown = new MarkdownRule()
val negativeProfit: Filter = new Filter {
def apply(pricing: Pricing) = pricing match {
case SubmitPricing =>
if ( < getWarehousePrice()) {
trace("negative profit " + pricing)
new ManualPricing(, , pricing)
}
else pricing
case _ => pricing
}
}
6
精选PPT
Function composition :2
val exceed: Filter = new Filter {
def changeCheck(a: Float, b: Float, per: Float): Boolean = (a - b) > a * per
def apply(pricing: Pricing) = pricing match {
case SubmitPricing =>
if (changeCheck(, ,
getThreholdPercentage()))
new ManualPricing(, , pricing)
else pricing
case _ => pricing
}
}
def followingRule(event: Event) =
following andThen
negativeProfit andThen
exce