Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Julien Richard-Foy edited this page Feb 7, 2018 · 90 revisions

This page should evolve over time, but already be useful now. When more official documentation is available, content can be replaced by links.

Collection Users

What are the breaking changes?

  • collection.breakOut no longer exists
  • Method to[C] was removed
  • MapProxy, SetProxy no longer exist
  • SynchronizedX no longer exist
  • SeqForwarder no longer exists
  • Implicit conversions between Scala and Java collections no longer exist (convert.ImplicitConversions / ImplicitConversionsToJava / ImplicitConversionsToScala) -- NOTE: they are not deprecated in 2.12.
  • MutableList is no longer public
  • TreeMap / TreeSet / BitSet: the to method is now called rangeTo
  • immutable.Set/Map: the + method no longer has an overload accepting multiple values, so Set(1) + (2, 3) is now Set(1) + 2 + 3
  • mutable.Set/Map no longer has a + method, so mutable.Set(1) + 2 is now mutable.Set(1).clone() += 2 (https://github.com/scala/collection-strawman/issues/375)
  • mutable.Set/Map no longer has an updated method, so mutable.Map(1 -> 2).updated(1, 3) is no mutable.Map(1 -> 2).clone() += 1 -> 3
  • Iterable no longer has a sameElements method, call .iterator() first
  • colleciton.Seq.union no longer exists, use ++
  • collection.Map no longer has - or -- methods
  • LinearSeq no longer has a companion-apply, use List()
  • HashSet.remove now returns an Option[A] instead of a Boolean
  • Iterable.partition invokes iterator twice and assumes it gets two iterators over the same elements. Strict subclasses override partition do perform only a single traversal.
  • List.union no longer exists, use :::
  • Stream.append is now Stream.lazyAppendAll, is now LazyList.lazyAppendAll

Are there new collection types?

Are there new operations on collections?

Are there new implementations of existing collection types (changes in performance characteristics)?

How do I cross-build my project against Scala 2.12 and Scala 2.13?

  • Compat library
  • Accept some deprecation warnings (?)
  • sbt's version-specific source folders if necessary, but should not be

Does scala.Seq change to mean scala.collection.immutable.Seq?

We have plans to change the scala.Seq alias, https://github.com/scala/collection-strawman/issues/149.

Historical discussion: https://groups.google.com/forum/#!topic/scala-internals/g_-gIWgB8Os

Collection Implementers

CanBuildFrom no longer exists - what were its uses and how can they be replaced?

How can I write generic extension methods?

How do I integrate my collection in the new design?

Read the draft document on the design of the Scala 2.13 collections: https://github.com/scalacenter/docs.scala-lang/blob/collection-strawman/_overviews/core/architecture-of-scala-collections.md

Which methods should I overload to support the “same result type” principle?

You want to add overloads to specialize a transformation operations such that they return a more specific result. Examples are:

  • map, on StringOps, when the mapping function returns a Char, should return a String (instead of an IndexedSeq),
  • map, on Map, when the mapping function returns a pair, should return a Map (instead of an Iterable),
  • map, on SortedSet, when an implicit Ordering is available for the resulting element type, should return a SortedSet (instead of a Set).

The following table lists transformation operations that might return a too wide type. You might want to overload these operations to return a more specific type.

Collection Operations
Iterable map, flatMap, collect, scanLeft, scanRight, groupMap, concat, zip, zipAll, unzip
Seq prepended, appended, prependedAll, appendedAll, padTo, patch
immutable.Seq updated
SortedSet map, flatMap, collect, zip
Map map, flatMap, collect, concat
immutable.Map updated, transform
SortedMap map, flatMap, collect, concat
immutable.SortedMap updated

How can I cross-build my collection implementation against 2.12 and 2.13?

Examples

Clone this wiki locally