title: Idiomatic Scala List Comprehension - first item that matches
body: <p>Folks,
    I've been writing some code in Scala lately to teach myself the language and in some recent experiments, I've used <a href="http://www.kotancode.com/2012/02/15/scalamud-scala-java-nlp/" rel="noreferrer">an NLP library to produce a set of part-of-speech tagged words</a> from a user's input.</p>
  
  <p>I want to write a function that gives me the first verb in the sentence. If there are no verbs, then I want to assume that the first word in the set is the verb (e.g. if the player just typed "who" or "uptime" , those are considered verbs by my game).</p>
  
  <p>The following is a block of code so ugly only a mother could love, and it stinks of imperative programming and I want to refactor it into something more like idiomatic Scala, ideally something that doesn't have a single "if" statement in it.</p>
  
  <pre><code>def firstVerb = {
      if (words.size == 1)
          words.head.value
      else {
          val outWords = words.filter( word =&gt; word.pos == Verb)
          if (outWords == Set.empty) 
              words.head.value
          else
              outWords.head.value 
      }
  }
  </code></pre>
  
  <p>The "words" variable is of type ListBuffer[EnrichedWord], where EnrichedWord is my class that contains a part of speech (pos, contains case objects like Verb, Noun, etc) and the original word (value).</p>
  
  <p>Any guidance you Scala geniuses can provide in refactoring this butt-ugly code would be fantastic.</p>