-
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
to(Seq) doesn't evaluate collection when called on a Seq #238
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NthPortal
previously approved these changes
Jul 25, 2019
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.
LGTM
Should LinearSeq
be handled as well?
@NthPortal yes, I guess |
I duplicated the logic for |
NthPortal
reviewed
Jul 25, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
NthPortal
reviewed
Jul 26, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
NthPortal
reviewed
Jul 26, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Show resolved
Hide resolved
NthPortal
reviewed
Jul 26, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Show resolved
Hide resolved
NthPortal
reviewed
Jul 26, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala
Outdated
Show resolved
Hide resolved
I can't reconcile the documentation with the observation that the extractor
object works, but the plain type match doesn't.
Maybe there is a bug in the implementation.
…On Sat, Jul 27, 2019, 19:47 Nth ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
<#238 (comment)>
:
> import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.Builder
import scala.collection.{immutable => i, mutable => m}
+/* builder optimized for a single ++= call, which returns identity on result if possible
+ * and defers to the underlying builder if not.
+ */
+private final class IdentityPreservingBuilder[A, CC[X] <: TraversableOnce[X]](that: Builder[A, CC[A]])(implicit ct: ClassTag[CC[A]])
+ extends Builder[A, CC[A]] {
+ var collection: CC[A] = null.asInstanceOf[CC[A]]
+ var ruined = false
+
+ final override def ++=(elems: TraversableOnce[A]): this.type =
+ elems match {
+ case ct(ca) if (collection == null && !ruined) => {
I guess it just doesn't work with HKT. It works fine with normal kinded
types:
Welcome to Scala 2.12.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_212).Type in expressions for evaluation. Or try :help.
scala> def test[A: reflect.ClassTag](elem: Any): Boolean = elem match {
| case a: A => true
| case _ => false
| }
test: [A](elem: Any)(implicit evidence$1: scala.reflect.ClassTag[A])Boolean
scala> test[Int]("foo")
res0: Boolean = false
scala> test[Int](1)
res1: Boolean = true
scala> test[String](1)
res2: Boolean = false
scala> test[String]("foo")
res3: Boolean = true
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#238?email_source=notifications&email_token=AAGXOEKA4Z74KEI3RQGFMMLQBSC2LA5CNFSM4IG2NCZ2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOB7YV5CY#discussion_r307972509>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGXOELU5RSW4W4NXVVYBXLQBSC2LANCNFSM4IG2NCZQ>
.
|
julienrf
reviewed
Jul 29, 2019
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala
Outdated
Show resolved
Hide resolved
julienrf
approved these changes
Jul 30, 2019
szeiger
approved these changes
Aug 1, 2019
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #236 Not so much about elegance as about getting the job done.