1 / 14
文档名称:

scala解决问题.pptx

格式:pptx   大小:639KB   页数:14页
下载后只包含 1 个 PPTX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

scala解决问题.pptx

上传人:992006838 2020/12/5 文件大小:639 KB

下载得到文件列表

scala解决问题.pptx

相关文档

文档介绍

文档介绍:Scala 解决问题
1
目录
Why scala
用scala 解决问题
More about scala
Q &A
Polyglot programming
2
Polyglot programming
Java
Scala
Ruby
Python
Groovy
C++
……
3
Why scala
Productivity
Maintainability
extensibility
4
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
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
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
exceed
def markdownRule(event: E