Skip to content

Commit

Permalink
Adds helper to create Shrink using LazyList
Browse files Browse the repository at this point in the history
This allows to use Shrink from scala 2.13 without getting deprecation
warnings on scala.collection.immutable.Stream
  • Loading branch information
froth committed Feb 14, 2020
1 parent cddf22f commit def2403
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ private[scalacheck] trait CogenVersionSpecific {
implicit def cogenLazyList[A: Cogen]: Cogen[LazyList[A]] =
Cogen.it(_.iterator)
}

private[scalacheck] trait ShrinkVersionSpecific {
/** Forward to Shrink instance factory */
def withLazyList[T](s: T => LazyList[T]): Shrink[T] = Shrink(s.andThen(_.toStream))
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ private[scalacheck] trait CogenVersionSpecific
private[scalacheck] trait GenSpecificationVersionSpecific {
def infiniteLazyList[T](g: => Gen[T]): Gen[Stream[T]] = Gen.infiniteStream(g)
}

private[scalacheck] trait ShrinkVersionSpecific
2 changes: 1 addition & 1 deletion src/main/scala/org/scalacheck/Shrink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait ShrinkLowPriority {
implicit def shrinkAny[T]: Shrink[T] = Shrink(_ => Stream.empty)
}

object Shrink extends ShrinkLowPriority {
object Shrink extends ShrinkLowPriority with ShrinkVersionSpecific {

import Stream.{cons, empty}
import scala.collection._
Expand Down

0 comments on commit def2403

Please sign in to comment.