In many cases, I want to apply the same filter
or map
function to a Seq
or ParSeq
collection. However I don't want to write the code twice.
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
}
}
Like the code above, for a Seq[String]
I need to apply fun
, I have to rewrite it again and the content are exactly the same.
How can I avoid it?