Skip to content

Instantly share code, notes, and snippets.

@dabd
Created March 24, 2016 14:24
Show Gist options
  • Save dabd/cf9ed4f92cadf76da550 to your computer and use it in GitHub Desktop.
Save dabd/cf9ed4f92cadf76da550 to your computer and use it in GitHub Desktop.
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Gen
def arbitraryCaseClass[A,C](f: A => C)(implicit t: Arbitrary[A]): Arbitrary[C] = Arbitrary(for(v <- arbitrary[A]) yield f(v))
type MyIdType = String
implicit val arbMyIdType: Arbitrary[MyIdType] = Arbitrary(Gen.identifier)
case class A(s: String, t: Int)
implicit def arbA = arbitraryCaseClass((A.apply _).tupled)
val a = arbitrary[A].sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment