-
-
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
Make Chain Arbitraries recursively build concatenations #2430
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e855055
Make Chain Arbitraries recursively build concatenations
johnynek 1d7dcc5
check some emptyness invariants
johnynek 02a2c00
improve code coverage by leveraging invariants
johnynek 7918e12
test next throws the right exception
johnynek be2d566
remove runtime check
johnynek 27648d7
make Chain iterators private
johnynek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,8 @@ sealed abstract class Chain[+A] { | |
else tail ++ rights.reduceLeft((x, y) => Append(y, x)) | ||
result = Some((seq.head, next)) | ||
case Empty => | ||
if (rights.isEmpty) { | ||
result = None | ||
} else { | ||
c = rights.last | ||
rights.trimEnd(1) | ||
} | ||
// Empty is only top level, it is never internal to an Append | ||
result = None | ||
} | ||
} | ||
// scalastyle:on null | ||
|
@@ -297,12 +293,8 @@ sealed abstract class Chain[+A] { | |
else rights.reduceLeft((x, y) => Append(y, x)) | ||
rights.clear() | ||
case Empty => | ||
if (rights.isEmpty) { | ||
c = null | ||
} else { | ||
c = rights.last | ||
rights.trimEnd(1) | ||
} | ||
// Empty is only top level, it is never internal to an Append | ||
c = null | ||
} | ||
} | ||
} | ||
|
@@ -429,10 +421,10 @@ object Chain extends ChainInstances { | |
fromSeq(as) | ||
|
||
// scalastyle:off null | ||
class ChainIterator[A](self: Chain[A]) extends Iterator[A] { | ||
var c: Chain[A] = if (self.isEmpty) null else self | ||
val rights = new collection.mutable.ArrayBuffer[Chain[A]] | ||
var currentIterator: Iterator[A] = null | ||
private class ChainIterator[A](self: Chain[A]) extends Iterator[A] { | ||
private[this] var c: Chain[A] = if (self.isEmpty) null else self | ||
private[this] val rights = new collection.mutable.ArrayBuffer[Chain[A]] | ||
private[this] var currentIterator: Iterator[A] = null | ||
|
||
override def hasNext: Boolean = (c ne null) || ((currentIterator ne null) && currentIterator.hasNext) | ||
|
||
|
@@ -461,8 +453,8 @@ object Chain extends ChainInstances { | |
rights.clear() | ||
currentIterator = seq.iterator | ||
currentIterator.next | ||
case Empty => | ||
go // This shouldn't happen | ||
case null | Empty => | ||
throw new java.util.NoSuchElementException("next called on empty iterator") | ||
} | ||
} | ||
|
||
|
@@ -473,10 +465,10 @@ object Chain extends ChainInstances { | |
|
||
|
||
// scalastyle:off null | ||
class ChainReverseIterator[A](self: Chain[A]) extends Iterator[A] { | ||
var c: Chain[A] = if (self.isEmpty) null else self | ||
val lefts = new collection.mutable.ArrayBuffer[Chain[A]] | ||
var currentIterator: Iterator[A] = null | ||
private class ChainReverseIterator[A](self: Chain[A]) extends Iterator[A] { | ||
private[this] var c: Chain[A] = if (self.isEmpty) null else self | ||
private[this] val lefts = new collection.mutable.ArrayBuffer[Chain[A]] | ||
private[this] var currentIterator: Iterator[A] = null | ||
|
||
override def hasNext: Boolean = (c ne null) || ((currentIterator ne null) && currentIterator.hasNext) | ||
|
||
|
@@ -505,8 +497,8 @@ object Chain extends ChainInstances { | |
lefts.clear() | ||
currentIterator = seq.reverseIterator | ||
currentIterator.next | ||
case Empty => | ||
go // This shouldn't happen | ||
case null | Empty => | ||
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. without the null here we had a match error previously on empty. |
||
throw new java.util.NoSuchElementException("next called on empty iterator") | ||
} | ||
} | ||
|
||
|
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
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
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.
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.
without the null here we had a match error previously on empty.
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.
Huh, I didn't even know you could pattern match on null 😬