如何将部分函数传递给包含部分函数的列表?

时间:2014-05-22 01:47:56

标签: scala

我有以下代码:

def bigger[T <% Ordered[T]](compare: T)(a: ResultSet, columnName: String): Boolean =
  a.getObject(columnName).asInstanceOf[T] > compare

var rules = List[(ResultSet,String) => Boolean]()   

rules += bigger[Int](1000) //doesn't work, compile error

val rule = bigger(1000) _ _ 
rules += rule //still doesn't work, compile error

我需要更改什么才能使其正常工作?

1 个答案:

答案 0 :(得分:2)

您只需使用一个_并使用+:=rules添加元素:

rules +:= bigger[Int](1000) _