scalacheck

io.github.martinhh.derived.scalacheck
object scalacheck

Public "API-entry-point" for derivation of scalacheck-typeclass-instances.

This does not provide derivation of Shrink-instances as that might not always be desired. You can opt in to derivation of Shrink-instances via shrink.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
scalacheck.type

Members list

Value members

Inherited methods

final override protected def buildSumGen[A](gens: List[Gen[A]], config: Option[RecursionFallback[A]]): Gen[A]

The logic for combining the Gen-instances of the various subtypes of a sum type (i.e. of a sealed trait or enum).

The logic for combining the Gen-instances of the various subtypes of a sum type (i.e. of a sealed trait or enum).

This can be overridden to customize that logic.

Type parameters

A

The "parent" sum type.

Value parameters

config

Optional configuration object - if a given instance of SumConfig[A] is in implicit scope of derivation, this will be a non-empty option containing that instance. Otherwise, this will be None.

gens

Gen-instances for all subtypes of a sum type.

Attributes

Returns

A Gen that was build based on the passed Gens.

Definition Classes
DefaultArbitraryDeriving -> ArbitraryDeriving
Inherited from:
DefaultArbitraryDeriving (hidden)
final inline def deriveArbitrary[T](using m: Of[T]): Arbitrary[T]

Derives an Arbitrary[T], ignoring any given Arbitrary[T] that is already in scope.

Derives an Arbitrary[T], ignoring any given Arbitrary[T] that is already in scope.

Note that this will recursively derive any missing Arbitrary-instances for any members/subtypes of T (unless such instances are already available in implicit scope).

This can be used to explicitly create given instances:

 case class Point(x: Double, y: Double)
 given Arbitrary[Point] = deriveArbitrary

Attributes

Inherited from:
ArbitraryDeriving (hidden)
final inline def deriveArbitraryShallow[T](using m: Of[T]): Arbitrary[T]

Derives an Arbitrary[T], ignoring any given Arbitrary[T] that is already in scope.

Derives an Arbitrary[T], ignoring any given Arbitrary[T] that is already in scope.

Note that this will ''not'' derive any missing Arbitrary-instances for any members of T if T is a product type (case class or tuple). It will however derive instances for any subtype of T if T is a sum type (sealed trait or enum) - the restriction for product types will then apply for those subtypes.

It can be used to explicitly create given instances:

 case class Point(x: Double, y: Double)
 given Arbitrary[Point] = deriveArbitraryShallow

The following however would fail:

 case class Foo(x: Int)
 case class Bar(foo: Foo)
 // fails with: No given instance of type org.scalacheck.Arbitrary[Foo] was found.
 given Arbitrary[Bar] = deriveArbitraryShallow

Attributes

Inherited from:
ArbitraryDeriving (hidden)
final inline def deriveCogen[T](using m: Of[T]): Cogen[T]

Attributes

Inherited from:
CogenDeriving (hidden)

Givens

Inherited givens

inline given anyGivenArbitrary[T]: Arbitrary[T]

Resolves an Arbitrary[T], using existing given instances or falling back to derivation.

Resolves an Arbitrary[T], using existing given instances or falling back to derivation.

Existing given instances (that are in scope) will be preferred over derivation.

Importing this will add derivation as fallback to implicit resolution of Arbitrary-instances.

Note that the following will not work and result in an "Infinite loop in function body":

 case class Point(x: Double, y: Double)
 given Arbitrary[Point] = anyGivenArbitrary

If you intend to derive Arbitrary-instances in that way, use deriveArbitrary instead.

Attributes

Inherited from:
ArbitraryDeriving (hidden)
inline given anyGivenCogen[T]: Cogen[T]

Attributes

Inherited from:
CogenDeriving (hidden)