Skip to content

Commit 4b534df

Browse files
committed
Address reviewers feedback
1 parent 4e721c9 commit 4b534df

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

blog/_posts/2018-06-13-scala-213-collections.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ title: Scala 2.13’s Collections
77

88
One more article about the standard collections, really? Indeed, during the last
99
18 months a lot of work has been done on the collections side and we’ve published
10-
several blog articles and given several talks to the explain various changes or
10+
several blog articles and given several talks to explain the various changes or
1111
challenges we were facing. This article summarizes **what is going
1212
to change from an end-user perspective**.
1313

14-
Even if you have thoroughly followed our previous blog posts and talks, this article
15-
gives you a good overview for summarizing the changes to your colleagues.
14+
In case you’ve thoroughly followed our previous blog posts and talks, you might
15+
not learn much from this article. Otherwise, this is the perfect opportunity
16+
to catch up on the topic in a few minutes!
1617

17-
The next section presents the internal changes in the collections implementation
18-
that might have some visible impact on the surface. Then, I will show why I think
18+
The next section presents the changes that are internal to the collections implementation
19+
but that might have some visible impact on the surface. Then, I will show why I think
1920
that the removal of `CanBuildFrom` made the API more beginner friendly. Next, I
2021
will introduce some new operations available in the collections. Finally, I
2122
will mention the main deprecations, the motivations behind them, and their
@@ -49,9 +50,9 @@ deprecated in favor of `LazyList` (see the last section).
4950

5051
I think the most visible change for end-users is that transformation operations
5152
don’t use `CanBuildFrom` anymore. I believe this will be quite visible despite our previous
52-
efforts to *hide* `CanBuildFrom` from the API documentation in the current collections.
53+
efforts to *hide* `CanBuildFrom` from the API documentation of the collections.
5354
Indeed, if you take a look at the
54-
[current `List` API](/api/2.12.6/scala/collection/immutable/List.html), the signature
55+
[old 2.12 `List` API](/api/2.12.6/scala/collection/immutable/List.html), the signature
5556
shown for the `map` operation does not mention `CanBuildFrom`:
5657

5758
![there is no CanBuildFrom](/resources/img/blog/scaladoc-list-map.png)
@@ -85,9 +86,9 @@ a single operation implementation, and `CanBuildFrom` was used to abstract over
8586
the various possible return types.
8687

8788
In the new collections we wanted to have simpler type signatures so that we
88-
can shoulder their actual form in the API documentation and auto-completion
89+
can show their actual signature in the API documentation, and auto-completion
8990
provided by IDEs is not scary. We achieve that by using overloading, as
90-
explained in more details in
91+
explained in more detail in
9192
[this blog article](/blog/2017/05/30/tribulations-canbuildfrom.html).
9293

9394
In practice, this means that the new `TreeMap` has three overloads of the
@@ -98,7 +99,7 @@ In practice, this means that the new `TreeMap` has three overloads of the
9899
These type signatures are the actual ones and they essentially translate
99100
“in types” what I’ve written above about the possible result types of `map`
100101
according to the type of elements returned by the transformation function `f`.
101-
I believe that the new API is simpler to understand.
102+
We believe that the new API is simpler to understand.
102103

103104
## New And Noteworthy
104105

@@ -107,7 +108,7 @@ present some of them.
107108

108109
### `groupMap`
109110

110-
A common pattern with the current collection is to use `groupBy`
111+
A common pattern with the old 2.12 collections is to use `groupBy`
111112
followed by `mapValues` to transform the groups. For instance,
112113
this is how we can index the names of a collection of users by
113114
their age:
@@ -161,14 +162,15 @@ users
161162
## Deprecations For Less Confusion
162163

163164
A consequence of cleaning and simplifying the collections framework
164-
is that several types or operations have been deprecated.
165+
is that several types or operations have been deprecated in Scala 2.13
166+
and will be removed in 2.14.
165167

166168
### `Iterable` Is The Top Collection Type
167169

168170
We felt that having a distinction between `Traversable` and `Iterable` was not
169171
worth it, so we removed `Traversable` (it is now an alias to `Iterable[A]`).
170172

171-
`IterableOnce[A]` is now the collection type at the top of the hierarchy.
173+
`Iterable[A]` is now the collection type at the top of the hierarchy.
172174
Its only abstract member is `def iterator: Iterator[A]`.
173175

174176
### `LazyList` Is Preferred Over `Stream`
@@ -180,7 +182,7 @@ the head and the tail are lazy, whereas in `Stream` only the tail is lazy.
180182

181183
### Insertion And Removal Operations Are Not Available On Generic Collections
182184

183-
In the current framework, the `scala.collection.Map` type has a `+` and a `-` operations
185+
In the old 2.12 framework, the `scala.collection.Map` type has a `+` and a `-` operations
184186
to add and remove entries. The semantics of these operations is to return a new collection
185187
with the added or removed entries, without changing the source collection.
186188

@@ -191,8 +193,8 @@ has `+` and `+=`, as well as `-` and `-=`.
191193

192194
Having all these operations can be handy in some cases but can also introduce confusion. If you want
193195
to use `+` or `-`, then you probably wanted to use an immutable collection type in the first place…
194-
Another example is the `updated` operation, which is available on mutable `Map` but returns a new
195-
collection.
196+
Consequently, `+`, `-` and `updated` have been moved from `scala.collection.Map` to `scala.collection.immutable.Map`,
197+
and `+` and `-` have been moved from `scala.collection.Set` to `scala.collection.immutable.Set`
196198

197199
We think that by deprecating these insertion and removal operations from generic collection
198200
types and by having distinct operations between the `mutable` and `immutable` branches we make

0 commit comments

Comments
 (0)