typelevel / typelevel/scalacheck
Gen.sequence seems to forget that ScalaCheck is a Scala lib (1.12.1)
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2k
- Forks
- 393
- Avg merge
- 6h 42m
- Merged PRs (30d)
- 4
Description
Consider the following console session, with ScalaCheck 1.12.1:
scala> import org.scalacheck.Gen
import org.scalacheck.Gen
scala> import org.scalacheck.Arbitrary._
import org.scalacheck.Arbitrary._
scala> val genInts = Gen.nonEmptyListOf(arbitrary[Int])
genInts: org.scalacheck.Gen[List[Int]] = org.scalacheck.Gen$$anon$2@393c86dd
scala> case class Bar(str: String, i: Int)
defined class Bar
scala> def genBarWith(i: Int) = for { str <- arbitrary[String] } yield Bar(str, i)
genBarWith: (i: Int)org.scalacheck.Gen[Bar]
scala> val genBarList = for { ints <- genInts; bars <- Gen.sequence { ints.map(genBarWith) } } yield bars
genBarList: org.scalacheck.Gen[java.util.ArrayList[Bar]] = org.scalacheck.Gen$$anon$6@2d97c1a
scala> val genBarList2 = for { ints <- genInts; bars <- Gen.sequence[List[Bar], Bar] { ints.map(genBarWith) } } yield bars
genBarList2: org.scalacheck.Gen[List[Bar]] = org.scalacheck.Gen$$anon$6@57b19137
Incidentally, the type parameters on genBarList2 cause IntelliJ to refuse to compile, although sbt and the REPL are fine with it.
To get back to Scala-land, I have to import scala.collection.JavaConverters._ and map on the generator with .map(_.asScala.toList).
Happy New Year! 😃
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the ScalaCheck 1.12.1 console session and inspect the Gen.sequence entry point, comparing the inferred result with the explicitly typed List result. Done means sequence preserves the expected Scala collection type without requiring JavaConverters or explicit type parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100