scala学习笔记:高阶函数
来源:互联网 发布:淘宝自己评价怎么看 编辑:程序博客网 时间:2024/05/06 21:51
scala> def power(y:Double)=(x:Double)=>Math.pow(x,y)warning: there were 1 deprecation warnings; re-run with -deprecation for detailspower: (y: Double)Double => Doublescala> val square=power(2)square: Double => Double = <function1>scala> val squareRoot=power(0.5)squareRoot: Double => Double = <function1>scala> square(10)res0: Double = 100.0scala> squareRoot(100)res1: Double = 10.0
也可以定义成:
scala> def power = (x:Double)=> ((y:Double) => math.pow(x, y))power: Double => Double => Doublescala> power(4)(3)res8: Double = 64.0
也可以写成:
scala> :paste// Entering paste mode (ctrl-D to finish)def power(x:Double,y:Double) = math.pow(x, y)def square=power(_:Double,2)def squareroot(x:Double)=power(x,0.5)square(3)squareroot(3)// Exiting paste mode, now interpreting.power: (x: Double, y: Double)Doublesquare: Double => Doublesquareroot: (x: Double)Doubleres8: Double = 1.7320508075688772
柯里化之后:
def power(x:Double)(y:Double) = math.pow(x, y)def square=power(_:Double)(2)square(3)def squareroot(x:Double)=power(x)(0.5)squareroot(3)
power: (x: Double)(y: Double)Doublesquare: Double => Doublesquareroot: (x: Double)Doubleres7: Double = 1.7320508075688772
0 0
- scala学习笔记:高阶函数
- scala 学习笔记 --高阶函数
- scala学习笔记--高阶函数
- scala学习笔记13 高阶函数
- scala学习笔记-高阶函数
- [Scala]Scala学习笔记八 高阶函数
- scala高阶函数学习
- scala学习笔记(十一) 高阶函数
- Scala 学习笔记(六)------定义高阶函数
- scala 自学笔记 高阶函数
- Scala学习——高阶函数
- scala学习之高阶函数
- Scala学习——高阶函数
- Scala高阶函数
- Scala 高阶函数
- scala------高阶函数
- Scala高阶函数
- scala高阶函数
- LVS+keepalived+nginx+tomcat部署实现
- 欢迎使用CSDN-markdown编辑器
- 信用卡因没有用产生了年费没交被冻结怎么消除?
- css知多少(2)——学习css的思路
- 如果你30岁还未赚到100万,你就应该看看了!
- scala学习笔记:高阶函数
- JQuery处理json与ajax返回JSON实例
- .net动态生成界面
- 第339天(37W+1)
- Altium Designer 10中pin properties选项卡里Electrical Type各选项的意思
- C++ string入门
- POJ 2763 Housewife Wind (树链剖分+线段树)
- 【HDU3068】最长回文【manacher】
- 【寻找百倍牛股】文化、经济格局及不协调投资