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.
精彩评论