Created
February 23, 2021 07:09
-
-
Save ambantis/d10910c6f3921087bde26455e952b4c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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