-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improve traverseViaChain API #3535
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ package cats | |
package kernel | ||
package instances | ||
|
||
import scala.collection.immutable.{IndexedSeq => ImIndexedSeq} | ||
import scala.collection.mutable | ||
import compat.scalaVersionSpecific._ | ||
|
||
@suppressUnusedImportWarningForScalaVersionSpecific | ||
object StaticMethods extends cats.kernel.compat.HashCompat { | ||
|
||
|
@@ -17,6 +19,22 @@ object StaticMethods extends cats.kernel.compat.HashCompat { | |
def iterator: Iterator[(K, V)] = m.iterator | ||
} | ||
|
||
/** | ||
* When you "own" this m, and will not mutate it again, this | ||
* is safe to call. It is unsafe to call this, then mutate | ||
* the original collection. | ||
* | ||
* You are giving up ownership when calling this method | ||
*/ | ||
def wrapMutableIndexedSeq[A](m: mutable.IndexedSeq[A]): ImIndexedSeq[A] = | ||
new WrappedIndexedSeq(m) | ||
|
||
private[kernel] class WrappedIndexedSeq[A](m: mutable.IndexedSeq[A]) extends ImIndexedSeq[A] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can never remember exactly how this works inside objects, but is there any reason to make this package-private (which is just public in the JVM API) instead of just private (which I think should be properly JVM-private)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not that I know of, I just copied the idiom below. Should I fix that up? |
||
override def length: Int = m.length | ||
override def apply(i: Int): A = m(i) | ||
override def iterator: Iterator[A] = m.iterator | ||
} | ||
|
||
// scalastyle:off return | ||
def iteratorCompare[A](xs: Iterator[A], ys: Iterator[A])(implicit ev: Order[A]): Int = { | ||
while (true) { | ||
|
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 is just miscellaneous clean-up, right, since
foreach
isn't used anywhere else?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. foreach is used exactly once and is private. Just use foreachUntil (or iterator).