Pattern-matching function I am new to Scala and I have written a function which uses pattern matching to filter words based on some conditions.  It seems to work correctly but I am suspect that I haven't used the Scala pattern matching in the best way.  I think this because each of my cases contain an if statement.  I have not seen any examples where people use if statements in pattern matching functions so I'm thinking there might be a better way of doing this.  Or maybe this particular usage does not fit well with pattern matching.

def getImportance(token:String,stopWords:Set[String])={
    token match{
      case t if t.length()==1 =&gt; 0
      case t if t.length()&gt;15 =&gt; 0
      case t if t.matches("\\p{Punct}+") =&gt; 0
      case t if stopWords.contains(t.toLowerCase()) =&gt; 0
      case _ =&gt; 1
    }
}
I don't think that using pattern matching is necessary in this case, you only have a few simple conditions that can be better represented with a simple if. See what you think about this solution:

def getImportance(token: String, stopWords: Set[String]) =
  if (token.length() == 1 || token.length() &gt; 15 ||
    token.matches("\\p{Punct}+") ||
    stopWords.contains(token.toLowerCase()))
      0
  else
      1


I believe it is simpler and easier to read. I think using patter matching for these simple cases only hinders the understanding of the code ;)