forked from typelevel/scalacheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScalaVersionSpecific.scala
46 lines (37 loc) · 1.29 KB
/
ScalaVersionSpecific.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* ScalaCheck
* Copyright (c) 2007-2021 Rickard Nilsson. All rights reserved.
* http://www.scalacheck.org
*
* This software is released under the terms of the Revised BSD License.
* There is NO WARRANTY. See the file LICENSE for the full text.
*/
package org.scalacheck
import rng.Seed
private[scalacheck] object ScalaVersionSpecific {
def toLazyList[T](i: IterableOnce[T]) = LazyList.from(i)
}
private[scalacheck] trait GenVersionSpecific {
/** Generates an infinite lazy list. */
def infiniteLazyList[T](g: => Gen[T]): Gen[LazyList[T]] = {
def unfold[A, S](z: S)(f: S => Option[(A, S)]): LazyList[A] = f(z) match {
case Some((h, s)) => h #:: unfold(s)(f)
case None => LazyList.empty
}
Gen.gen { (p, seed0) =>
new Gen.R[LazyList[T]] {
val result: Option[LazyList[T]] = Some(unfold(seed0)(s => Some(g.pureApply(p, s) -> s.next)))
val seed: Seed = seed0.next
}
}
}
}
private[scalacheck] trait GenSpecificationVersionSpecific
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))
}