Skip to content

Remove scalacheck fork by implementing buildableOfCollCond #358

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

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

mdedetrich
Copy link
Contributor

About this change - What it does

Replaces fork of scalacheck with official upstream one and as a result implements listOfFillCond natively.

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.infiniteLazyList which can be used to implement this functionality (see typelevel/scalacheck#849 (comment))

@mdedetrich mdedetrich force-pushed the remove-scalacheck-fork branch 2 times, most recently from fb2d47f to f1f2ad8 Compare January 16, 2023 07:09
@mdedetrich mdedetrich force-pushed the remove-scalacheck-fork branch from f1f2ad8 to 438bce5 Compare January 20, 2023 10:31
@mdedetrich mdedetrich force-pushed the remove-scalacheck-fork branch 4 times, most recently from ffe959a to bd93d92 Compare February 7, 2023 08:24
Gen.infiniteLazyList(g).map { ll =>
val it = ll.iterator
val bldr = evb.builder
while (!cond(bldr.result()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mdedetrich mdedetrich force-pushed the remove-scalacheck-fork branch 3 times, most recently from 9137e2a to 8a6ef46 Compare February 8, 2023 00:13
@mdedetrich mdedetrich force-pushed the remove-scalacheck-fork branch from 8a6ef46 to e5ae5a0 Compare February 8, 2023 23:01
@mdedetrich mdedetrich merged commit ef1642c into main Feb 9, 2023
@mdedetrich mdedetrich deleted the remove-scalacheck-fork branch February 9, 2023 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants