title: Scala: ResultSet translation into a different kinds of multimaps
body: <p>I am going to create wrapper over JDBC ResultSet in Scala.<br>
  This wrapper is intended to be a function <code>ResultSet => ParticularType</code>.<br>
  The problem is I can't find a common solution for making MultiMaps.</p>
  
  <p>Here is the way I am fetching collections:</p>
  
  <pre>
  abstract class CollectionCreator[C] extends (ResultSet => C) {  
    def apply(rs: ResultSet): C = {  
      do { append(rs) } while (rs.next)  
      returnCollection()  
    }  
    def append(rs: ResultSet)  
    def returnCollection(): C 
  }
  </pre>
  
  <p>Next goes maps creation. It is an implementation of collection creation and it is not abstract due to map non-abstractness (it is always backended with HashMap in my implementation).<br>
  In my opinion, it should look like this:</p>
  
  <pre>
  class MapCreator[K,IV](keyCreator: ResultSet => K, valueCreator: ResultSet => IV)
    extends CollectionCreator[Map[K, Place for V]] {
  
    type V = IV
    val intermediateMap = new HashMap[K, V]
  
    override def append(rs: ResultSet) {
      appendToMap(keyCreator(rs), valueCreator(rs))
    }
  
    def appendToMap(key: K, value: IV) {
      intermediateMap(key) = value
    }
  
    override def returnCollection(): Map[K,V] = intermediateMap.toMap
  }
  </pre>
  
  <p>If it works, I would write ListMultiMap creation this way:</p>
  
  <pre>
  class ListMultiMapCreator[K,IV](keyCreator: ResultSet => K, valueCreator: ResultSet => IV)
    extends MapCreator[K, Place for V](keyCreator, valueCreator) {
  
    override type V = List[IV]
  
    override def appendToMap(key: K, value: IV) {
      intermediateMap(key) = intermediateMap.get(key) match {
        case Some(values) => values.::(value)
        case None         => List(value)
      }
    }
  }
  </pre>  
  
  <p>The problem is I can't use <code>V</code> at <code>Place for V</code> because it is not declared then.<br>
  I feel like abstract types is the good solution but don't know how to treat them right.</p>
  
  <p>What is the correct way of such a collections creation?</p>
  
  <p>I am also not sure if it is possible to override abstract types that were already defined higher in the class hierarchy.</p>