All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.timepit.refined.scalacheck.any.scala Maven / Gradle / Ivy

There is a newer version: 0.11.2
Show newest version
package eu.timepit.refined.scalacheck

import eu.timepit.refined.api.{RefType, Validate}
import org.scalacheck.Arbitrary

/**
 * Module that provides an `Arbitrary` instance for any refined type
 * `F[T, P]`.
 *
 * This instance uses the `Arbitrary` instance of the base type `T` and
 * the corresponding `Validate[T, P]` instance of the refinement to filter
 * out invalid values. For most refinements this will cause ScalaCheck to
 * fail because this instance will discard too many values.
 */
object any extends AnyInstances

trait AnyInstances {

  implicit def arbitraryFromValidate[F[_, _], T, P](implicit
      rt: RefType[F],
      v: Validate[T, P],
      arb: Arbitrary[T]
  ): Arbitrary[F[T, P]] =
    arbitraryRefType(arb.arbitrary.filter(v.isValid))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy