开发者

control structure

开发者 https://www.devze.com 2023-02-08 19:38 出处:网络
Finding difficult understanding f开发者_StackOverflowollowing control structure scala> def twice(op: Double => Double, x: Double) = op(op(x))

Finding difficult understanding f开发者_StackOverflowollowing control structure

scala> def twice(op: Double => Double, x: Double) = op(op(x))

twice: (op: (Double) => Double,x: Double)Double

scala> twice( _ + 1,5)

res0: Double = 7.0


op: Double => Double

is a function that takes a Double and returns a Double as a result. twice is a method takes a number, calls op on it, and then calls op on the result.

_ + 1

is a function that takes a value and adds one to it.

You can probably figure out the rest from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消