-
-
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
Changes from 4 commits
e855055
1d7dcc5
02a2c00
7918e12
be2d566
27648d7
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 |
---|---|---|
|
@@ -37,12 +37,9 @@ 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 | ||
if (rights.nonEmpty) throw new IllegalStateException(s"found internal Empty in $this") | ||
result = None | ||
} | ||
} | ||
// scalastyle:on null | ||
|
@@ -297,12 +294,9 @@ 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 | ||
if (rights.nonEmpty) throw new IllegalStateException(s"found internal Empty in $this") | ||
c = null | ||
} | ||
} | ||
} | ||
|
@@ -461,8 +455,8 @@ object Chain extends ChainInstances { | |
rights.clear() | ||
currentIterator = seq.iterator | ||
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. 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. Huh, I didn't even know you could pattern match on null 😬 |
||
throw new java.util.NoSuchElementException("next called on empty iterator") | ||
} | ||
} | ||
|
||
|
@@ -505,8 +499,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") | ||
} | ||
} | ||
|
||
|
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.
should we just remove this since 1. we believe this to be true, 2. we have laws to catch this. By removing entirely we improve code coverage and we possibly slightly improve performance.
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.
Yeah sounds good 👍