-
Notifications
You must be signed in to change notification settings - Fork 72
FAQ
This page should evolve over time, but already be useful now. When more official documentation is available, content can be replaced by links.
-
collection.breakOut
no longer exists -
Method
to[C]
was removed (Note: it might be reintroduced but deprecated) -
MapProxy
,SetProxy
no longer exist -
SynchronizedX
no longer exist -
SeqForwarder
no longer exists -
MutableList
no longer exists -
TreeMap
/TreeSet
/BitSet
: theto
,until
andfrom
methods are now calledrangeTo
,rangeUntil
andrangeFrom
, respectively. -
immutable.Set/Map
: the+
method no longer has an overload accepting multiple values, soSet(1) + (2, 3)
is nowSet(1) + 2 + 3
-
mutable.Set/Map
no longer has a+
method, somutable.Set(1) + 2
is nowmutable.Set(1).clone() += 2
(https://github.com/scala/collection-strawman/issues/375) -
mutable.Set/Map
no longer has anupdated
method, somutable.Map(1 -> 2).updated(1, 3)
is nomutable.Map(1 -> 2).clone() += 1 -> 3
-
Iterable
no longer has asameElements
method, call.iterator()
first -
collection.Seq.union
is deprecated, use++
-
collection.Set/Map
no longer have+
methods, so use++
(???) -
collection.Map
no longer has-
or--
methods -
LinearSeq
no longer has a companion-apply, useList()
-
Iterable.partition
invokesiterator
twice on non-strict collections and assumes it gets two iterators over the same elements. Strict subclasses overridepartition
do perform only a single traversal. -
Stream.append
is deprecated, useStream.lazyAppendedAll
-
scala.Seq[+A]
is nowscala.collection.immutable.Seq[A]
(this also affects varargs methods). -
The new collections makes more use of overloading. For instance,
Map.map
is overloaded:scala> Map(1 -> "a").map def map[B](f: ((Int, String)) => B): scala.collection.immutable.Iterable[B] def map[K2, V2](f: ((Int, String)) => (K2, V2)): scala.collection.immutable.Map[K2,V2]
Type inference has been improved so that
Map(1 -> "a").map(x => (x._1 + 1, x._2))
works, the compiler can infer the parameter type for the function literal. However, using a method reference in 2.13.0-M4 (improvement are on the way for 2.13.0) does not work, and an explicit eta-expansion is necessary:scala> def f(t: (Int, String)) = (t._1 + 1, t._2) scala> Map(1 -> "a").map(f) ^ error: missing argument list for method f Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing `f _` or `f(_)` instead of `f`. scala> Map(1 -> "a").map(f _) res10: scala.collection.immutable.Map[Int,String] = ChampHashMap(2 -> a)
-
StreamView no longer exists https://github.com/scala/collection-strawman/issues/543
The scala-collection-contrib
module provides decorators enriching the collections with new operations. You can
think of this artifact as an incubator: if we get evidence that these operations should be part of the core,
we might eventually move them.
The following collections are provided:
-
MultiSet
(both mutable and immutable) -
SortedMultiSet
(both mutable and immutable) -
MultiDict
(both mutable and immutable) -
SortedMultiDict
(both mutable and immutable)
The scala-collection-contrib
module provides decorators enriching the collections with new operations. You can
think of this artifact as an incubator: if we get evidence that these operations should be part of the core,
we might eventually move them.
The new operations are provided via an implicit enrichment. You need to add the following import to make them available:
import strawman.collection.decorators._
The following operations are provided:
-
Seq
intersperse
-
Map
-
zipByKey
/join
/zipByKeyWith
-
mergeByKey
/fullOuterJoin
/mergeByKeyWith
/leftOuterJoin
/rightOuterJoin
-
Are there new implementations of existing collection types (changes in performance characteristics)?
The default Set
and Map
are backed by a ChampHashSet
and a ChampHashMap
, respectively. The performance characteristics are the same but the
operation implementations are faster. These data structures also have a lower memory footprint.
mutable.Queue
and mutable.Stack
now use mutable.ArrayDeque
. This data structure supports constant time index access, and amortized constant time
insert and remove operations.
- Compat library
- Accept some deprecation warnings (?)
- sbt's version-specific source folders if necessary, but should not be
Examples
- https://github.com/scala/scala-parser-combinators/pull/134/files
- https://github.com/scala/scala-xml/compare/master...lrytz:newCollections?expand=1
- Some other examples are listed here: https://github.com/scala/community-builds/issues/710
-
ArraySeq
is deprecated. 2.12 had bothWrappedArray
andArraySeq
, whereWrappedArray
has specialized subclasses for primitive arrays.ArraySeq
is backed by an object array, primitives are boxed. In 2.13,WrappedArray
can be used either way for primitive arrays (TODO: document how).
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
You want to add overloads to specialize a transformation operations such that they return a more specific result. Examples are:
-
map
, onStringOps
, when the mapping function returns aChar
, should return aString
(instead of anIndexedSeq
), -
map
, onMap
, when the mapping function returns a pair, should return aMap
(instead of anIterable
), -
map
, onSortedSet
, when an implicitOrdering
is available for the resulting element type, should return aSortedSet
(instead of aSet
).
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 |