据我所知,带有隐式参数的函数使用起来很烦人。适当的类型是(您的选择):
(String, Double, Any) => Format => Option[Int] // As written
Format => (String, Double, Any) => Option[Int] // Conceptually works more like this
String => Double => Any => Format => Option[Int] // Completely curried
(String, Double, Any, Format) => Option[Int] // Closest to how the JVM sees the method
但部分应用该功能效果不佳。您可以烦人地注释所有类型以获得最新版本:
class Format {} // So the example works
def tsadd(s: String, d: Double, a: Any)(implicit f: Format): Option[Int] = None
scala> tsadd(_: String, _: Double, _: Any)(_: Format)
res2: (String, Double, Any, Format) => Option[Int] = <function4>
但将自己的代码写成任何你想要的形状并不困难:
def example(f: Format => (String, Double, Any) => Option[Int]) = f
scala> example(f => { implicit val fm=f; tsadd _ })
res3: (Format) => (String, Double, Any) => Option[Int] = <function1>
当然,如果您在创建列表时已经知道隐式值,则只需要类型
(String, Double, Any) => Option[Int]
然后你分配这样的功能
tsadd _