diff --git a/src/main/scala/org/scalacheck/Arbitrary.scala b/src/main/scala/org/scalacheck/Arbitrary.scala index e6f057d6c..814a0ee71 100644 --- a/src/main/scala/org/scalacheck/Arbitrary.scala +++ b/src/main/scala/org/scalacheck/Arbitrary.scala @@ -357,17 +357,17 @@ private[scalacheck] sealed trait ArbitraryLowPriority { Arbitrary(Gen.oneOf(arbitrary[T].map(Success(_)), arbitrary[Throwable].map(Failure(_)))) /** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container - * (such as lists, arrays, lazy lists, etc). The maximum size of the container + * (such as lists, arrays, streams / lazy lists, etc). The maximum size of the container * depends on the size generation parameter. */ implicit def arbContainer[C[_],T](implicit - a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Iterable[T] + a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T] ): Arbitrary[C[T]] = Arbitrary(buildableOf[C[T],T](arbitrary[T])) /** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container * (such as maps). The maximum size of the container depends on the size * generation parameter. */ implicit def arbContainer2[C[_,_],T,U](implicit - a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Iterable[(T,U)] + a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Traversable[(T,U)] ): Arbitrary[C[T,U]] = Arbitrary(buildableOf[C[T,U],(T,U)](arbitrary[(T,U)])) implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = { diff --git a/src/main/scala/org/scalacheck/Gen.scala b/src/main/scala/org/scalacheck/Gen.scala index 0e740c11c..3384e0f0c 100644 --- a/src/main/scala/org/scalacheck/Gen.scala +++ b/src/main/scala/org/scalacheck/Gen.scala @@ -577,7 +577,7 @@ object Gen extends GenArities with GenVersionSpecific { //// List Generators //// - /** Generates a container of any Iterable type for which there exists an + /** Generates a container of any Traversable type for which there exists an * implicit [[org.scalacheck.util.Buildable]] instance. The elements in the * container will be generated by the given generator. The size of the * generated container is limited by `n`. Depending on what kind of container @@ -585,47 +585,47 @@ object Gen extends GenArities with GenVersionSpecific { * `n`, but not more. If the given generator fails generating a value, the * complete container generator will also fail. */ def buildableOfN[C,T](n: Int, g: Gen[T])(implicit - evb: Buildable[T,C], evt: C => Iterable[T] + evb: Buildable[T,C], evt: C => Traversable[T] ): Gen[C] = - sequence[C,T](Iterable.fill(n)(g)) suchThat { c => + sequence[C,T](Traversable.fill(n)(g)) suchThat { c => // TODO: Can we guarantee c.size == n (See issue #89)? c.forall(g.sieveCopy) } - /** Generates a container of any Iterable type for which there exists an + /** Generates a container of any Traversable type for which there exists an * implicit [[org.scalacheck.util.Buildable]] instance. The elements in the * container will be generated by the given generator. The size of the * container is bounded by the size parameter used when generating values. */ def buildableOf[C,T](g: Gen[T])(implicit - evb: Buildable[T,C], evt: C => Iterable[T] + evb: Buildable[T,C], evt: C => Traversable[T] ): Gen[C] = sized(s => choose(0, s max 0).flatMap(buildableOfN[C,T](_,g))) suchThat { c => if (c == null) g.sieveCopy(null) else c.forall(g.sieveCopy) } - /** Generates a non-empty container of any Iterable type for which there + /** Generates a non-empty container of any Traversable type for which there * exists an implicit [[org.scalacheck.util.Buildable]] instance. The * elements in the container will be generated by the given generator. The * size of the container is bounded by the size parameter used when * generating values. */ def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit - evb: Buildable[T,C], evt: C => Iterable[T] + evb: Buildable[T,C], evt: C => Traversable[T] ): Gen[C] = sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0) /** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */ def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit - evb: Buildable[T,C[T]], evt: C[T] => Iterable[T] + evb: Buildable[T,C[T]], evt: C[T] => Traversable[T] ): Gen[C[T]] = buildableOfN[C[T],T](n,g) /** A convenience method for calling `buildableOf[C[T],T](g)`. */ def containerOf[C[_],T](g: Gen[T])(implicit - evb: Buildable[T,C[T]], evt: C[T] => Iterable[T] + evb: Buildable[T,C[T]], evt: C[T] => Traversable[T] ): Gen[C[T]] = buildableOf[C[T],T](g) /** A convenience method for calling `nonEmptyBuildableOf[C[T],T](g)`. */ def nonEmptyContainerOf[C[_],T](g: Gen[T])(implicit - evb: Buildable[T,C[T]], evt: C[T] => Iterable[T] + evb: Buildable[T,C[T]], evt: C[T] => Traversable[T] ): Gen[C[T]] = nonEmptyBuildableOf[C[T],T](g) /** Generates a list of random length. The maximum length depends on the @@ -656,7 +656,7 @@ object Gen extends GenArities with GenVersionSpecific { * is equal to calling containerOfN[Map,T,U](n,g). */ def mapOfN[T,U](n: Int, g: Gen[(T,U)]) = buildableOfN[Map[T,U],(T,U)](n,g) - /** Generates an infinite lazy list. */ + /** Generates an infinite stream. */ def infiniteStream[T](g: => Gen[T]): Gen[Stream[T]] = { def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = f(z) match { case Some((h, s)) => h #:: unfold(s)(f) diff --git a/src/main/scala/org/scalacheck/Shrink.scala b/src/main/scala/org/scalacheck/Shrink.scala index 8d397e86a..423f85aff 100644 --- a/src/main/scala/org/scalacheck/Shrink.scala +++ b/src/main/scala/org/scalacheck/Shrink.scala @@ -30,7 +30,7 @@ object Shrink extends ShrinkLowPriority { import LazyList.{cons, empty} import scala.collection._ - /** Interleaves two lazy lists */ + /** Interleaves two streams / lazy lists */ private def interleave[T](xs: LazyList[T], ys: LazyList[T]): LazyList[T] = if(xs.isEmpty) ys else if(ys.isEmpty) xs @@ -45,12 +45,12 @@ object Shrink extends ShrinkLowPriority { def shrink[T](x: T)(implicit s: Shrink[T]): LazyList[T] = s.shrink(x) /** Shrink a value, but also return the original value as the first element in - * the resulting lazy list */ + * the resulting stream / lazy list */ def shrinkWithOrig[T](x: T)(implicit s: Shrink[T]): LazyList[T] = cons(x, s.shrink(x)) /** Shrink instance of container */ - implicit def shrinkContainer[C[_],T](implicit v: C[T] => Iterable[T], s: Shrink[T], + implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T], b: Buildable[T,C[T]] ): Shrink[C[T]] = Shrink { xs: C[T] => val ys = v(xs) @@ -59,7 +59,7 @@ object Shrink extends ShrinkLowPriority { } /** Shrink instance of container2 */ - implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Iterable[(T,U)], s: Shrink[(T,U)], + implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Traversable[(T,U)], s: Shrink[(T,U)], b: Buildable[(T,U),C[T,U]] ): Shrink[C[T,U]] = Shrink { xs: C[T,U] => val ys = v(xs) diff --git a/src/main/scala/org/scalacheck/util/Buildable.scala b/src/main/scala/org/scalacheck/util/Buildable.scala index d1fd5730d..d8ad2de3a 100644 --- a/src/main/scala/org/scalacheck/util/Buildable.scala +++ b/src/main/scala/org/scalacheck/util/Buildable.scala @@ -26,8 +26,8 @@ trait Buildable[T,C] extends Serializable { * Factory instances implementing Serializable, so that the objects capturing those can be * serializable too. */ +// Names are `..CanBuildFrom` for binary compatibility. Change to `..Factory` in a major release. object SerializableCanBuildFroms { - // Names are `..CanBuildFrom` for binary compatibility. Change to `..Factory` in a major release. implicit def listCanBuildFrom[T]: Factory[T, List[T]] = ScalaVersionSpecific.listFactory implicit def bitsetCanBuildFrom[T]: Factory[Int, BitSet] = ScalaVersionSpecific.bitsetFactory implicit def mapCanBuildFrom[T, U]: Factory[(T, U), Map[T, U]] = ScalaVersionSpecific.mapFactory @@ -41,7 +41,7 @@ object Buildable { } import java.util.ArrayList - implicit def buildableArrayList[T] = new Buildable[T,ArrayList[T]] { + implicit def buildableArrayList[T]: Buildable[T, ArrayList[T]] = new Buildable[T,ArrayList[T]] { def builder = new ArrayListBuilder[T] } diff --git a/src/test/scala/org/scalacheck/ShrinkSpecification.scala b/src/test/scala/org/scalacheck/ShrinkSpecification.scala index 69dd74bd0..930e00a4f 100644 --- a/src/test/scala/org/scalacheck/ShrinkSpecification.scala +++ b/src/test/scala/org/scalacheck/ShrinkSpecification.scala @@ -105,7 +105,7 @@ object ShrinkSpecification extends Properties("Shrink") { /* Ensure that shrink[T] terminates. (#244) * - * Let's say shrinking "terminates" when the lazy list of values + * Let's say shrinking "terminates" when the stream / lazy list of values * becomes empty. We can empirically determine the longest possible * sequence for a given type before termination. (Usually this * involves using the type's MinValue.) diff --git a/src/test/scala/org/scalacheck/util/BuildableSpecification.scala b/src/test/scala/org/scalacheck/util/BuildableSpecification.scala index 2830a10d5..4764f026d 100644 --- a/src/test/scala/org/scalacheck/util/BuildableSpecification.scala +++ b/src/test/scala/org/scalacheck/util/BuildableSpecification.scala @@ -17,7 +17,7 @@ import ScalaVersionSpecific._ object BuildableSpecification { def container[C[_]](implicit evb: Buildable[String, C[String]], - evt: C[String] => Iterable[String] + evt: C[String] => Traversable[String] ) = Gen.containerOf[C, String](Gen.alphaStr) implicit val listGen: Gen[List[String]] = container[List]