Skip to content

Instantly share code, notes, and snippets.

@ambantis
Created February 23, 2021 07:09
Show Gist options
  • Save ambantis/d10910c6f3921087bde26455e952b4c8 to your computer and use it in GitHub Desktop.
Save ambantis/d10910c6f3921087bde26455e952b4c8 to your computer and use it in GitHub Desktop.
// scala 2.13.4
import $ivy.`org.scalacheck::scalacheck:1.15.3`
import org.scalacheck.Gen
import scala.collection.AbstractIterator
// 11 -> 22 -> 33
class CircularIterator extends AbstractIterator[Int] {
private var value: Int = 11
private def inc: Unit = value match {
case 11 => value = 22
case 22 => value = 33
case 33 => value = 11
}
override def hasNext: Boolean = true
override def next(): Int = {
val result = value
inc
result
}
}
def genCircularInt: Gen[Int] = {
val it = new CircularIterator
Gen.const(0).map(_ => it.next())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment