Skip to content

Commit

Permalink
Merge pull request #605 from ashawley/use-self
Browse files Browse the repository at this point in the history
Switch to self instead of Gen.this
  • Loading branch information
ashawley authored Jan 9, 2020
2 parents 76cc373 + 1a932eb commit 9847100
Showing 1 changed file with 8 additions and 8 deletions.
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 @@ -179,10 +179,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

0 comments on commit 9847100

Please sign in to comment.