Scala filter on two conditions

richsoni picture richsoni · Jun 20, 2012 · Viewed 43.1k times · Source

I would like to filter my data set on two conditions at once.

Is it possible?

I want something like this:

mystuff = mystuff.filter(_.isX && _.name == "xyz")

Answer

Alex Wilson picture Alex Wilson · Jun 20, 2012

Using slightly less concise lambda syntax:

mystuff = mystuff.filter(x => (x.isX && x.name == "xyz"))

You can find more detail on Scala anonymous function syntax here.