Skip to content

Commit 013192b

Browse files
committed
Simplify scalacheck shrinker
1 parent 12a53ec commit 013192b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scalacheck/src/main/scala/com/github/simy4/coregex/scalacheck/CoregexInstances.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ trait CoregexInstances {
3838
val coregex = CoregexParser.getInstance().parse(Pattern.compile(regex.value))
3939
Shrink.withLazyList { larger =>
4040
val rng = new RandomRNG()
41-
LazyList
42-
.iterate(coregex.minLength())(remainder => (remainder * 2) + 1)
43-
.takeWhile(remainder => remainder < larger.length)
44-
.map(remainder => coregex.sized(remainder).generate(rng).asInstanceOf[Matching[A, Regex]])
41+
LazyList.unfold(coregex.minLength()) { remainder =>
42+
Option.when(remainder < larger.length) {
43+
(coregex.sized(remainder).generate(rng).asInstanceOf[Matching[A, Regex]], (remainder * 2) + 1)
44+
}
45+
}
4546
}
4647
}
4748
}

0 commit comments

Comments
 (0)