There’s an increasingly heated debate about Scala’s complexity. A recent post talks about Scala’s "true complexity": the terrifying intricacy you will encounter, if you try to extend Scala’s Collections Library with a method that achieves the "perfect" behavior.

Yet it also might be worth asking: what are the motivations of these "perfect" behaviors? Are they always desirable?

One important aspect of the "perfect" collection behavior is the magical uniform return type principle. Sloppily speaking, this means that transforming a collection should give you another collection of the same kind. For instance:

// Filtering a List gives you a filtered List
scala> List(1,2,3,4).filter(_%2==0)
res: List[Int] = List(2, 4)

// Mapping a Set gives you a mapped Set
scala> Set(1,2,3,4).map(1+)
res: scala.collection.immutable.Set[Int] = Set(2, 3, 4, 5)

// Uniform return type at both compile time and runtime
scala> val iterable : Iterable[Int] = Set(1,2,3,4)
iterable: Iterable[Int] = Set(1, 2, 3, 4)

res: Iterable[Int] = Set(2, 3, 4, 5)

// Works for Strings, too
scala> "E is the most frequent letter in English".map(
     |    c ...