-
Notifications
You must be signed in to change notification settings - Fork 87
Add TraversableOnce.knownSize #143
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
Changes from 2 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package test.scala.collection | ||
|
||
import org.junit.{Assert, Test} | ||
|
||
import scala.collection.compat._ | ||
|
||
class ExtensionsTest { | ||
@Test | ||
def `TraversableOnce.knownSize`(): Unit = { | ||
Assert.assertEquals(-1, Iterator(1).knownSize) | ||
Assert.assertEquals(1, List(1).knownSize) | ||
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. The size of Actually I realize only now that |
||
} | ||
} |
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.
In 2.13 the size of an
IndexedSeq
’s iterator is known: https://github.com/scala/scala/blob/2.13.x/src/library/scala/collection/IndexedSeqView.scala#L27You can use
Iterator.from(1)
instead.