在许多情况下,我想将相同的filter
ormap
函数应用于 a Seq
orParSeq
集合。但是我不想写两次代码。
def fun(data:ParSeq[String], num_start:Int,num_end:Int) = {
data filter { x=>
val temp = extract_number(x)
num_start <= temp && temp <= num_end
}
}
就像上面的代码一样,对于一个Seq[String]
我需要申请的fun
,我必须重新重写一遍,内容完全一样。我怎样才能避免它?
您可以使用GenSeq[String]
.
无论ParSeq
和Seq
延伸GenSeq
,这通常是为了曾经有将使用取决于你传递给他们集合类型并行或串行操作的功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句