-
Notifications
You must be signed in to change notification settings - Fork 87
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
Add an iterator()
alias to iterator
#7
Conversation
I’m on the fence with the changes on parentheses. On one hand, there are some advantages of having a more disciplined used of parentheses (although, as noted by @Ichoran in the linked discussion, it is hard to find a really robust principle on when to use parentheses). But on the other hand that a source of incompatibilities between 2.13 and prior Scala versions… The trick I’m using here works for |
@@ -30,15 +30,31 @@ package object compat { | |||
simpleCBF(fact.newBuilder) | |||
|
|||
implicit class IterableFactoryExtensionMethods[CC[X] <: GenTraversable[X]](private val fact: GenericCompanion[CC]) { | |||
def from[A](source: TraversableOnce[A]): CC[A] = fact.apply(source.toSeq: _*) | |||
def from[A](source: TraversableOnce[A]): CC[A] = (fact.newBuilder[A] ++= source).result() |
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.
This won't work for lazy collections. You don't want Stream.from(otherStream)
to force anything.
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.
Stream
uses a lazy builder, so this code doesn’t force the source. I’ve added a test for that.
Also add more support for `from` to more companion types, and make their implementation more efficient.
Now the real question is “do we really want to keep |
Closed because of scala/scala#6620 |
Add SeqDecorator.replaced
We already have a scalafix rule that translates
.iterator
calls to.iterator()
. This rule can be applied to all the code bases to make them compatible with 2.13. However, once the rule has been applied the code won’t be compatible with 2.12 (or previous Scala version) anymore…This PR introduces an
iterator()
extension method for Scala 2.12 so that after the application of the scalafix rule, the code can still compile with 2.12.A second commit makes it possible to write
newBuilder()
instead ofnewBuilder
, in 2.12.Also, related discussion: scala/collection-strawman#520