Skip to content
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

Switch to self instead of Gen.this #605

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main/scala/org/scalacheck/Gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ sealed abstract class Gen[+T] extends Serializable { self =>

/** A class supporting filtered operations. */
final class WithFilter(p: T => Boolean) {
def map[U](f: T => U): Gen[U] = Gen.this.suchThat(p).map(f)
def flatMap[U](f: T => Gen[U]): Gen[U] = Gen.this.suchThat(p).flatMap(f)
def withFilter(q: T => Boolean): WithFilter = Gen.this.withFilter(x => p(x) && q(x))
def map[U](f: T => U): Gen[U] = self.suchThat(p).map(f)
def flatMap[U](f: T => Gen[U]): Gen[U] = self.suchThat(p).flatMap(f)
def withFilter(q: T => Boolean): WithFilter = self.withFilter(x => p(x) && q(x))
}

/** Evaluate this generator with the given parameters */
Expand Down Expand Up @@ -107,11 +107,11 @@ sealed abstract class Gen[+T] extends Serializable { self =>
def suchThat(f: T => Boolean): Gen[T] = new Gen[T] {
def doApply(p: P, seed: Seed) =
p.useInitialSeed(seed) { (p0, s0) =>
val res = Gen.this.doApply(p0, s0)
res.copy(s = { (x: T) => res.sieve(x) && f(x) })
val res = self.doApply(p0, s0)
res.copy(s = { (x:T) => res.sieve(x) && f(x) })
}
override def sieveCopy(x: Any) =
try Gen.this.sieveCopy(x) && f(x.asInstanceOf[T])
try self.sieveCopy(x) && f(x.asInstanceOf[T])
catch { case _: java.lang.ClassCastException => false }
}

Expand Down Expand Up @@ -178,10 +178,10 @@ sealed abstract class Gen[+T] extends Serializable { self =>
def label(l: String): Gen[T] = new Gen[T] {
def doApply(p: P, seed: Seed) =
p.useInitialSeed(seed) { (p0, s0) =>
val r = Gen.this.doApply(p0, s0)
val r = self.doApply(p0, s0)
r.copy(l = r.labels + l)
}
override def sieveCopy(x: Any) = Gen.this.sieveCopy(x)
override def sieveCopy(x: Any) = self.sieveCopy(x)
}

/** Put a label on the generator to make test reports clearer */
Expand Down