Is it possible to lift custom generating function into Gen
?
For example, generating ObjectId
s for mongo.
import org.mongodb.scala.bson.ObjectId
import org.scalacheck.Gen
val genObjectId: Gen[ObjectId] = Gen.lift(() => new ObjectId)
The only possible solution I've found is to hack the generator like:
val genObjectId: Gen[ObjectId] = Gen.numChar.map(_ => new ObjectId)
Generating ObjectId
s using Gen.hexChar
is irrelevant because:
Gen.delay(Gen.const(new ObjectId))
delay
's argument is by-name, so every attempt to generate a value will construct a new ObjectId
.