This repository was archived by the owner on Jan 20, 2026. It is now read-only.
Remove scalacheck fork by implementing buildableOfCollCond - #358
Merged
Conversation
mdedetrich
force-pushed
the
remove-scalacheck-fork
branch
2 times, most recently
from
January 16, 2023 07:09
fb2d47f to
f1f2ad8
Compare
mdedetrich
force-pushed
the
remove-scalacheck-fork
branch
from
January 20, 2023 10:31
f1f2ad8 to
438bce5
Compare
mdedetrich
force-pushed
the
remove-scalacheck-fork
branch
4 times, most recently
from
February 7, 2023 08:24
ffe959a to
bd93d92
Compare
mdedetrich
requested review from
RyanSkraba,
ahmedsobeh,
jlprat,
reta and
snuyanzin
February 7, 2023 09:26
reta
reviewed
Feb 7, 2023
| Gen.infiniteLazyList(g).map { ll => | ||
| val it = ll.iterator | ||
| val bldr = evb.builder | ||
| while (!cond(bldr.result())) |
Contributor
There was a problem hiding this comment.
The only option I see (without introducing the mutable state) is something like this (pseudo code, probably needs some scalafication):
while (true) {
val result = bldr.result();
if (cond(result)) {
return result;
}
bldr ++= it.next()
}
Contributor
Author
There was a problem hiding this comment.
Thanks for recommendation, I wanted to avoid this because it involved having to circumvent Scala's lint warnings but I managed to find a way. Just pushed it now to see if tests pass.
Contributor
Author
There was a problem hiding this comment.
So I tried a solution, i.e.
@SuppressWarnings(
Array(
"scalafix:DisableSyntax.while",
"scalafix:DisableSyntax.return"
)
)
@scala.annotation.nowarn("msg=return statement uses an exception")
private def buildableOfCollCond[C <: Iterable[T], T](cond: C => Boolean, g: Gen[C])(implicit
evb: Buildable[T, C]
): Gen[C] =
Gen.infiniteLazyList(g).map { ll =>
val it = ll.iterator
val bldr = evb.builder
while (true) {
val result = bldr.result()
if (cond(result)) {
return result
}
bldr ++= it.next()
}
return bldr.result()
}And it didn't work/terminate. Don't have time to look at this now so I will make an issue to look at it later as an improvement.
reta
approved these changes
Feb 7, 2023
mdedetrich
force-pushed
the
remove-scalacheck-fork
branch
3 times, most recently
from
February 8, 2023 00:13
9137e2a to
8a6ef46
Compare
mdedetrich
force-pushed
the
remove-scalacheck-fork
branch
from
February 8, 2023 23:01
8a6ef46 to
e5ae5a0
Compare
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
About this change - What it does
Replaces fork of scalacheck with official upstream one and as a result implements
listOfFillCondnatively.Why this way
Initially a fork of scalacheck was made in order to implement the ability to create a continuously growing generator. The fork was done because at the time I thought it was not possible to implement this without modifying the core of scalacheck. It turns out that I was incorrect in this, scalacheck has a
Gen.infiniteLazyListwhich can be used to implement this functionality (see typelevel/scalacheck#849 (comment))