-
Notifications
You must be signed in to change notification settings - Fork 326
Scala 2.13 Collections Rework blog post #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
here's a PDF preview: if |
ugh, that PDF doesn't look anything like it looks in Safari :-\ here's the HTML+assets, from Chrome: |
I don't even know where to open an issue because all of the options that I tried failed. OSX default Ruby can't install gems anymore because of the protected system dirs. Installed another copy via brew, then installed Jekyll. Running it fails with:
So I used bundler (after finding out how to install it):
OK, let's try a newer version:
Update that as well? Nope:
|
Thanks for the zip, the page looks good at first glance. |
Try cding into the |
@heathermiller |
I had a similar problem a few months ago after upgrading to MacOS Sierra and trying to add a Jekyll plugin (unrelated to scala-lang). Turned out to be related to XCode after upgrading OSX. Maybe this is helpful to you: inukshuk/jekyll-scholar#171 |
You could try to use ruby installed by homebrew, instaead of the macOS default. |
@szeiger Your post looks super nice! I was thinking that we could merge our posts together and then break them down into two posts, one to explain the context, the problem and the goal, and a second one giving more technical informations about the design decisions we took. What do you think? |
@julienrf It's a bit longer than I planned but that's because the topics I cover naturally lead to one another, so I think it makes sense to keep them together. I left out anything that wasn't part of that story arc. Do you think there are enough interesting detail topics left for a second post? |
- All `Map` types: `T <:< (_, _)` ("must be a Tuple2") | ||
- All sorted collections (like `TreeSet`): `Ordering[T]` ("must have an Ordering") | ||
- String (not a collection type per se but it gets many collection methods as extension methods): `T <:< Char` ("must be a Char") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add:
- Array (same situation as String):
T: ClassTag
("must have a class-tag")
OK, I understand your point. Maybe it is better to complete your post with some missing information (e.g. how to try the collections and what are the new features). |
- All sorted collections (like `TreeSet`): `Ordering[T]` ("must have an Ordering") | ||
- String (not a collection type per se but it gets many collection methods as extension methods): `T <:< Char` ("must be a Char") | ||
|
||
This covers most uses of `CanBuildFrom` in a much simpler way. The most important use cases that cannot be supported by the new design are `collection.breakOut` (for building a different collection type directly without an extra conversion step) and `to` (for converting to a different collection type for which a `CanBuildFrom` is available). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add:
The new design provides alternative ways to achieve the same effects.
``` | ||
|
||
This has the advantage that we can overload `to` to cover maps (and maybe also other constrained collection types) which is not possible in the current design (where `to` only works for unary type constructors). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: Should we keep the old version of to
in a compatibility kit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be part of a migration library. If we want to provide source compatibility for building on 2.12 and 2.13 we probably need extra libraries for both versions.
@odersky Updated. @julienrf I'd rather put the instructions for adding the published version to your project into our @heathermiller There's a minor update for XCode queued. I'll give that a try. @lrytz I'm already using the Homebrew version. |
Might be better to go back in time with Ruby and see if 2.4 is the problem. The Travis build uses 2.2, FYI. That works for me. I use rbenv for switching ruby versions which you can get from Homebrew. There's a hint of cargo cult on my part, but this works for me:
|
@julienrf Do you have any updates for this or can we publish it tomorrow? |
Well, I'd rather we didn't publish a blog post on the weekend. So let's wait until Monday. A lot more people see it then. |
Sounds good. I'll push an update on Monday with the new date. |
@szeiger Thanks for asking. I think your post is fine, I will not push additional updates. |
|
||
Unlike all other collection types, `Seq` is not the immutable version but the generic one that encompasses both, mutable and immutable sequences. The reason for this is that the Scala specification represents varargs as type `scala.Seq` (and it should not have to rely on any type outside the top-level `scala` package). Since varargs in Java (and on the JVM) are really mutable arrays, the default `Seq` has to allow mutable collections. | ||
|
||
In practice though, this kind of array can be treated as quasi-immutable, so we plan to add a new `ImmutableArray` wrapper in the new design which can be used for varags, thereby removing the need for a non-immutable default `Seq` type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "varargs", not "varags"
res3: Class[Seq[_]] = interface scala.collection.Seq | ||
``` | ||
|
||
Unlike all other collection types, `Seq` is not the immutable version but the generic one that encompasses both, mutable and immutable sequences. The reason for this is that the Scala specification represents varargs as type `scala.Seq` (and it should not have to rely on any type outside the top-level `scala` package). Since varargs in Java (and on the JVM) are really mutable arrays, the default `Seq` has to allow mutable collections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is scala.Seq
a third type? I don't think it is. It's just an alias for scala.collection.Seq
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct, scala.Seq
== scala.collection.Seq
, unlike Predef.Set
and Predef.Map
which are aliases to scala.collection.immutable.Set
and scala.collection.immutble.Map
respectively.
9382d3b
to
331ee5c
Compare
Fixed typo, updated date, squashed. |
Hm, ok, so question is should we still publish this today? I just merged @olafurpg's blog post about a new release of Scalafix. I'm happy to merge this if you'd like, but two blog articles on the same day tend to contend with each other. We can also push merge tomorrow. Whatever you prefer @szeiger and @julienrf, just say the word. |
331ee5c
to
595c1ee
Compare
Updated with tomorrow's date. Let's give Scalafix more than 5 minutes in the top spot :-) |
Alrighty, thanks for your understanding @szeiger :) |
Merging now :) 🍷 |
@julienrf Here's my blog post (updated from the first draft yesterday) for the collections rework.
I hope it looks OK in Jekyll. I gave up after wasting an hour trying to install that Ruby crap with its choice of broken dependency managers.