title: Scala - Nested loops, for-comprehension and type of the final iteration
body: <p>I'm relatively new to scala and made some really simple programs succesfully.
  However, now that I'am trying some real world problem resolution, things are getting a little bit harder...</p>
  
  <p>I want to read some files into 'Configuration' objects, using various 'FileTypeReader' subtypes that can 'accept' certain files (one for each FileTypeReader subtype) and return an Option[Configuration] if it can extract a configuration from it.</p>
  
  <p>I'm trying to avoid the imperative style and wrote, for exemple, something like this (using scala-io, scaladoc for Path here <a href="http://jesseeichar.github.com/scala-io-doc/0.3.0/api/index.html#scalax.file.Path" rel="nofollow">http://jesseeichar.github.com/scala-io-doc/0.3.0/api/index.html#scalax.file.Path</a> ) :</p>
  
  <pre><code>(...)
  trait FileTypeReader {
     import scalax.file.Path
     def accept(aPath : Path) : Option[Configuration]
  }
  var readers : List[FileTypeReader] = ...// list of concrete readers
  var configurations = for (
            nextPath &lt;- Path(someFolder).children();
            reader &lt;- readers
        ) yield reader.accept(nextPath);
  (...)
  </code></pre>
  
  <p>Of course, that does not work, for-comprehensions return a collection of the first generator type (here, some IterablePathSet).</p>
  
  <p>Since I tried many variant and feel like running in circle, I beg for you advices on that matter to solve my - trivial ? - problem with elegance ! :)</p>
  
  <p>Many thanks in advance,</p>
  
  <p>sni.</p>