title: Why is a scala Set casted to a Vector instead of a List?
body: <p>I wonder why a <code>Set[A]</code> is converted to a <code>Vector[A]</code> if I ask for a <code>Seq[A]</code> subclass? To illustrate this take the following example:</p>
  
  <pre><code>val A = Set("one", "two")
  val B  = Set("one", "two", "three")
  
  def f(one: Seq[String], other : Seq[String]) = {
    one.intersect(other) match {
      case head :: tail =&gt; head
      case _ =&gt; "unknown"
    }
  }
  
  f(A.to, B.to)
  </code></pre>
  
  <p>This function will return "unknown" instead of one. The reason is that <code>A.to</code> will be casted to a <code>Vector[String]</code>. The cons operator (<code>::</code>) is not defined for Vectors but for Lists so the second case is applied and "unknown" is returned. To fix this problem I could use the <code>+:</code> operator which is defined for all <code>Seqs</code> or convert the Set to List (<code>A.to[List]</code>). So my (academic) question is:</p>
  
  <p>Why does <code>A.to</code> returns a Vector. At least according to the <a href="https://docs.scala-lang.org/overviews/collections/overview.html" rel="nofollow noreferrer">scala docs</a> the default implementation of <code>Seq</code> is <code>LinearSeq</code> and the default of this is <code>List</code>. What did I got wrong? </p>