How does CanBuildFrom know whether a type can build from another?

Viewed 2374

I read the official doc but I can't still understand how it works. For example:

class A {
  type Self
}
def seqToSet[T <: A](seq: Seq[T])
                    (implicit cbf: CanBuildFrom[Seq[T], T#Self, Set[T]]) {}

The above code can be compiled... but how? How does Scala know a Set can be built from a Seq? And how could it ensure a T#Self(literally any type) can be put into Set[T]?

2 Answers
Related