Skip to content

Commit 1c79131

Browse files
committed
Go back to using Traversable instead of Iterable
This is a no-op for 2.13, as Traversable is a (deprecated) alias for Iterable. For 2.10-2.12, this ensures that the signatures don't change due to cross-building with 2.13.
1 parent 5ba8ddf commit 1c79131

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/main/scala/org/scalacheck/Arbitrary.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,17 @@ private[scalacheck] sealed trait ArbitraryLowPriority {
357357
Arbitrary(Gen.oneOf(arbitrary[T].map(Success(_)), arbitrary[Throwable].map(Failure(_))))
358358

359359
/** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container
360-
* (such as lists, arrays, lazy lists, etc). The maximum size of the container
360+
* (such as lists, arrays, streams / lazy lists, etc). The maximum size of the container
361361
* depends on the size generation parameter. */
362362
implicit def arbContainer[C[_],T](implicit
363-
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Iterable[T]
363+
a: Arbitrary[T], b: Buildable[T,C[T]], t: C[T] => Traversable[T]
364364
): Arbitrary[C[T]] = Arbitrary(buildableOf[C[T],T](arbitrary[T]))
365365

366366
/** Arbitrary instance of any [[org.scalacheck.util.Buildable]] container
367367
* (such as maps). The maximum size of the container depends on the size
368368
* generation parameter. */
369369
implicit def arbContainer2[C[_,_],T,U](implicit
370-
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Iterable[(T,U)]
370+
a: Arbitrary[(T,U)], b: Buildable[(T,U),C[T,U]], t: C[T,U] => Traversable[(T,U)]
371371
): Arbitrary[C[T,U]] = Arbitrary(buildableOf[C[T,U],(T,U)](arbitrary[(T,U)]))
372372

373373
implicit def arbEnum[A <: java.lang.Enum[A]](implicit A: reflect.ClassTag[A]): Arbitrary[A] = {

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -577,55 +577,55 @@ object Gen extends GenArities with GenVersionSpecific {
577577

578578
//// List Generators ////
579579

580-
/** Generates a container of any Iterable type for which there exists an
580+
/** Generates a container of any Traversable type for which there exists an
581581
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
582582
* container will be generated by the given generator. The size of the
583583
* generated container is limited by `n`. Depending on what kind of container
584584
* that is generated, the resulting container may contain fewer elements than
585585
* `n`, but not more. If the given generator fails generating a value, the
586586
* complete container generator will also fail. */
587587
def buildableOfN[C,T](n: Int, g: Gen[T])(implicit
588-
evb: Buildable[T,C], evt: C => Iterable[T]
588+
evb: Buildable[T,C], evt: C => Traversable[T]
589589
): Gen[C] =
590-
sequence[C,T](Iterable.fill(n)(g)) suchThat { c =>
590+
sequence[C,T](Traversable.fill(n)(g)) suchThat { c =>
591591
// TODO: Can we guarantee c.size == n (See issue #89)?
592592
c.forall(g.sieveCopy)
593593
}
594594

595-
/** Generates a container of any Iterable type for which there exists an
595+
/** Generates a container of any Traversable type for which there exists an
596596
* implicit [[org.scalacheck.util.Buildable]] instance. The elements in the
597597
* container will be generated by the given generator. The size of the
598598
* container is bounded by the size parameter used when generating values. */
599599
def buildableOf[C,T](g: Gen[T])(implicit
600-
evb: Buildable[T,C], evt: C => Iterable[T]
600+
evb: Buildable[T,C], evt: C => Traversable[T]
601601
): Gen[C] =
602602
sized(s => choose(0, s max 0).flatMap(buildableOfN[C,T](_,g))) suchThat { c =>
603603
if (c == null) g.sieveCopy(null) else c.forall(g.sieveCopy)
604604
}
605605

606-
/** Generates a non-empty container of any Iterable type for which there
606+
/** Generates a non-empty container of any Traversable type for which there
607607
* exists an implicit [[org.scalacheck.util.Buildable]] instance. The
608608
* elements in the container will be generated by the given generator. The
609609
* size of the container is bounded by the size parameter used when
610610
* generating values. */
611611
def nonEmptyBuildableOf[C,T](g: Gen[T])(implicit
612-
evb: Buildable[T,C], evt: C => Iterable[T]
612+
evb: Buildable[T,C], evt: C => Traversable[T]
613613
): Gen[C] =
614614
sized(s => choose(1, s max 1).flatMap(buildableOfN[C,T](_,g))) suchThat(_.size > 0)
615615

616616
/** A convenience method for calling `buildableOfN[C[T],T](n,g)`. */
617617
def containerOfN[C[_],T](n: Int, g: Gen[T])(implicit
618-
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
618+
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
619619
): Gen[C[T]] = buildableOfN[C[T],T](n,g)
620620

621621
/** A convenience method for calling `buildableOf[C[T],T](g)`. */
622622
def containerOf[C[_],T](g: Gen[T])(implicit
623-
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
623+
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
624624
): Gen[C[T]] = buildableOf[C[T],T](g)
625625

626626
/** A convenience method for calling `nonEmptyBuildableOf[C[T],T](g)`. */
627627
def nonEmptyContainerOf[C[_],T](g: Gen[T])(implicit
628-
evb: Buildable[T,C[T]], evt: C[T] => Iterable[T]
628+
evb: Buildable[T,C[T]], evt: C[T] => Traversable[T]
629629
): Gen[C[T]] = nonEmptyBuildableOf[C[T],T](g)
630630

631631
/** Generates a list of random length. The maximum length depends on the
@@ -656,7 +656,7 @@ object Gen extends GenArities with GenVersionSpecific {
656656
* is equal to calling <code>containerOfN[Map,T,U](n,g)</code>. */
657657
def mapOfN[T,U](n: Int, g: Gen[(T,U)]) = buildableOfN[Map[T,U],(T,U)](n,g)
658658

659-
/** Generates an infinite lazy list. */
659+
/** Generates an infinite stream. */
660660
def infiniteStream[T](g: => Gen[T]): Gen[Stream[T]] = {
661661
def unfold[A, S](z: S)(f: S => Option[(A, S)]): Stream[A] = f(z) match {
662662
case Some((h, s)) => h #:: unfold(s)(f)

src/main/scala/org/scalacheck/Shrink.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Shrink extends ShrinkLowPriority {
3030
import LazyList.{cons, empty}
3131
import scala.collection._
3232

33-
/** Interleaves two lazy lists */
33+
/** Interleaves two streams / lazy lists */
3434
private def interleave[T](xs: LazyList[T], ys: LazyList[T]): LazyList[T] =
3535
if(xs.isEmpty) ys
3636
else if(ys.isEmpty) xs
@@ -45,12 +45,12 @@ object Shrink extends ShrinkLowPriority {
4545
def shrink[T](x: T)(implicit s: Shrink[T]): LazyList[T] = s.shrink(x)
4646

4747
/** Shrink a value, but also return the original value as the first element in
48-
* the resulting lazy list */
48+
* the resulting stream / lazy list */
4949
def shrinkWithOrig[T](x: T)(implicit s: Shrink[T]): LazyList[T] =
5050
cons(x, s.shrink(x))
5151

5252
/** Shrink instance of container */
53-
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Iterable[T], s: Shrink[T],
53+
implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T],
5454
b: Buildable[T,C[T]]
5555
): Shrink[C[T]] = Shrink { xs: C[T] =>
5656
val ys = v(xs)
@@ -59,7 +59,7 @@ object Shrink extends ShrinkLowPriority {
5959
}
6060

6161
/** Shrink instance of container2 */
62-
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Iterable[(T,U)], s: Shrink[(T,U)],
62+
implicit def shrinkContainer2[C[_,_],T,U](implicit v: C[T,U] => Traversable[(T,U)], s: Shrink[(T,U)],
6363
b: Buildable[(T,U),C[T,U]]
6464
): Shrink[C[T,U]] = Shrink { xs: C[T,U] =>
6565
val ys = v(xs)

src/main/scala/org/scalacheck/util/Buildable.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ trait Buildable[T,C] extends Serializable {
2626
* Factory instances implementing Serializable, so that the objects capturing those can be
2727
* serializable too.
2828
*/
29+
// Names are `..CanBuildFrom` for binary compatibility. Change to `..Factory` in a major release.
2930
object SerializableCanBuildFroms {
30-
// Names are `..CanBuildFrom` for binary compatibility. Change to `..Factory` in a major release.
3131
implicit def listCanBuildFrom[T]: Factory[T, List[T]] = ScalaVersionSpecific.listFactory
3232
implicit def bitsetCanBuildFrom[T]: Factory[Int, BitSet] = ScalaVersionSpecific.bitsetFactory
3333
implicit def mapCanBuildFrom[T, U]: Factory[(T, U), Map[T, U]] = ScalaVersionSpecific.mapFactory
@@ -41,7 +41,7 @@ object Buildable {
4141
}
4242

4343
import java.util.ArrayList
44-
implicit def buildableArrayList[T] = new Buildable[T,ArrayList[T]] {
44+
implicit def buildableArrayList[T]: Buildable[T, ArrayList[T]] = new Buildable[T,ArrayList[T]] {
4545
def builder = new ArrayListBuilder[T]
4646
}
4747

src/test/scala/org/scalacheck/ShrinkSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ object ShrinkSpecification extends Properties("Shrink") {
105105

106106
/* Ensure that shrink[T] terminates. (#244)
107107
*
108-
* Let's say shrinking "terminates" when the lazy list of values
108+
* Let's say shrinking "terminates" when the stream / lazy list of values
109109
* becomes empty. We can empirically determine the longest possible
110110
* sequence for a given type before termination. (Usually this
111111
* involves using the type's MinValue.)

src/test/scala/org/scalacheck/util/BuildableSpecification.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import ScalaVersionSpecific._
1717
object BuildableSpecification {
1818
def container[C[_]](implicit
1919
evb: Buildable[String, C[String]],
20-
evt: C[String] => Iterable[String]
20+
evt: C[String] => Traversable[String]
2121
) = Gen.containerOf[C, String](Gen.alphaStr)
2222

2323
implicit val listGen: Gen[List[String]] = container[List]

0 commit comments

Comments
 (0)