Skip to content

Commit 50fa674

Browse files
authored
Merge pull request #709 from non/topic/reliable-nonempty
Avoid filtering in nonEmptyBuildableOf.
2 parents 6282460 + fda0c1e commit 50fa674

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/scala/org/scalacheck/Gen.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ object Gen extends GenArities with GenVersionSpecific {
826826
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
827827
evb: Buildable[T,C], evt: C => Traversable[T]
828828
): Gen[C] =
829-
buildableOf(g)(evb, evt).suchThat(c => evt(c).size > 0)
829+
sized(s => choose(1, Integer.max(s, 1)))
830+
.flatMap(n => buildableOfN(n, g)(evb, evt))
830831

831832
/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
832833
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit

0 commit comments

Comments
 (0)