在scala中使用Find函数

时间:2015-08-03 14:12:38

标签: scala

case class Meth(name: String, typ: Type, np : Int )
def lookupMethod(cls:String,mth:String,np:Int,list:List[MyClassType]):Option[Meth] =
{ .....
val findMeth = listMeth.find( a = > ( a.name == mth && a.np == np) )
.....
}

我有listMeth:List [Meth],我想找到具有“ mth 名称和“ np “参数。我上面的代码不起作用,所以如何修复它?

1 个答案:

答案 0 :(得分:3)

=>没有空格:

 def lookupMethod(cls: String, mth: String, np: Int, list: List[MyClassType]): Option[Meth] = {
    listMeth.find(a => a.name == mth && a.np == np)
  }