Scala推理_
我是scala(fxnl编程)的新手,不过我在下面的一些地方把它放在上下文中Scala推理_,scala,type-inference,Scala,Type Inference,我是scala(fxnl编程)的新手,不过我在下面的一些地方把它放在上下文中 list.map(_ * 1) 我不能完全理解这句话 val story = (catch _) andThen (eat _) 虽然我可以从电话中推断 story(new Cat, new Bird) 下划线用作参数位置的占位符,我想了解它背后的概念。语句 不正确-因为catch是关键字 但这是正确的: scala> def caught(x:Int) = x + 8 caught: (x: Int)
list.map(_ * 1)
我不能完全理解这句话
val story = (catch _) andThen (eat _)
虽然我可以从电话中推断
story(new Cat, new Bird)
下划线用作参数位置的占位符,我想了解它背后的概念。语句
不正确-因为catch是关键字
但这是正确的:
scala> def caught(x:Int) = x + 8
caught: (x: Int)Int
scala> def eat(x:Int) = x + 3
eat: (x: Int)Int
scala> val story = (caught _) andThen (eat _) // story is function.
story: Int => Int = <function1>
scala> story(90) // You put 90 - parameter for caught (first _). It returns 90 + 8 and put it to eat (second _). eat function return 98 + 3
res0: Int = 101
scala>def捕获(x:Int)=x+8
捕获:(x:Int)Int
scala>defeat(x:Int)=x+3
吃:(x:Int)Int
scala>val story=(捕获)和(吃)//story是函数。
故事:Int=>Int=
scala>story(90)//您将90-参数放在catch(first)上。它返回90+8并将其放入食物中(秒)。eat函数返回98+3
res0:Int=101
语句
不正确-因为catch是关键字
但这是正确的:
scala> def caught(x:Int) = x + 8
caught: (x: Int)Int
scala> def eat(x:Int) = x + 3
eat: (x: Int)Int
scala> val story = (caught _) andThen (eat _) // story is function.
story: Int => Int = <function1>
scala> story(90) // You put 90 - parameter for caught (first _). It returns 90 + 8 and put it to eat (second _). eat function return 98 + 3
res0: Int = 101
scala>def捕获(x:Int)=x+8
捕获:(x:Int)Int
scala>defeat(x:Int)=x+3
吃:(x:Int)Int
scala>val story=(捕获)和(吃)//story是函数。
故事:Int=>Int=
scala>story(90)//您将90-参数放在catch(first)上。它返回90+8并将其放入食物中(秒)。eat函数返回98+3
res0:Int=101
浏览此答案,了解下划线的用法:感谢您在搜索时发现此为,浏览此答案,了解下划线的用法:感谢您在搜索时发现此为