all*_*cer 0 scala implicit higher-order-functions
我有一个这样的功能:
def getSomething: (String, Future[String]) => String = {
case (name, surname) if (name == "Joe", surname.map(s => s == "Doe")) => "Is ok"
}
Run Code Online (Sandbox Code Playgroud)
但是编译器说他需要executionContext这里的map函数。我试图做一些魔术:
def getSomething (implicit e: ExecutionContext): (String, Future[String]) => String{...}
Run Code Online (Sandbox Code Playgroud)
或者
def getSomething: (String, Future[String])(implicit e: ExecutionContext) => String{...}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。是否可以将隐式参数传递给这样的功能?或者我可以用其他方式来做吗?
def getSomething (implicit e: ExecutionContext): (String, Future[String]) => String = ...
Run Code Online (Sandbox Code Playgroud)
应该管用。
你不能写
(String, Future[String]) => (implicit e: ExecutionContext) => String
Run Code Online (Sandbox Code Playgroud)
隐式函数将出现在 Scala 3 中。
http://dotty.epfl.ch/docs/reference/contextual/context-functions.html
http://dotty.epfl.ch/blog/2016/12/05/implicit-function-types.html
| 归档时间: |
|
| 查看次数: |
113 次 |
| 最近记录: |