开发者

control structure

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜