From e79ee1d4fba6a7c48f66849788e02ed4f22b1324 Mon Sep 17 00:00:00 2001 From: "Frank S. Thomas" Date: Tue, 26 Jul 2016 23:13:39 +0200 Subject: [PATCH] wip --- .../eu/timepit/refined/scalacheck/numeric.scala | 13 +++++++------ .../eu/timepit/refined/api/RefinedType.scala | 15 +++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/contrib/scalacheck/shared/src/main/scala/eu/timepit/refined/scalacheck/numeric.scala b/contrib/scalacheck/shared/src/main/scala/eu/timepit/refined/scalacheck/numeric.scala index 0e7bc0b8e..c4deb4fee 100644 --- a/contrib/scalacheck/shared/src/main/scala/eu/timepit/refined/scalacheck/numeric.scala +++ b/contrib/scalacheck/shared/src/main/scala/eu/timepit/refined/scalacheck/numeric.scala @@ -1,7 +1,7 @@ package eu.timepit.refined package scalacheck -import eu.timepit.refined.api.{ RefType, Validate } +import eu.timepit.refined.api.{ RefinedType, RefType } import eu.timepit.refined.numeric._ import eu.timepit.refined.scalacheck.util.{ Adjacent, Bounded } import org.scalacheck.{ Arbitrary, Gen } @@ -22,12 +22,13 @@ object numeric { * * This is like ScalaCheck's `Gen.chooseNum` but for refined types. */ - def chooseRefinedNum[F[_, _], T: Numeric: Choose, P](min: F[T, P], max: F[T, P])( + def chooseRefinedNum[FTP, T: Numeric: Choose](min: FTP, max: FTP)( implicit - rt: RefType[F], - v: Validate[T, P] - ): Gen[F[T, P]] = - Gen.chooseNum(rt.unwrap(min), rt.unwrap(max)).filter(v.isValid).map(rt.unsafeWrap) + rt: RefinedType.AuxT[FTP, T] + ): Gen[FTP] = + Gen.chooseNum(rt.unwrap(min), rt.unwrap(max)) + .filter(rt.validate.isValid) + .map(rt.wrapUnsafe) /// diff --git a/core/shared/src/main/scala/eu/timepit/refined/api/RefinedType.scala b/core/shared/src/main/scala/eu/timepit/refined/api/RefinedType.scala index 5bc1fe7f2..6ed560fdf 100644 --- a/core/shared/src/main/scala/eu/timepit/refined/api/RefinedType.scala +++ b/core/shared/src/main/scala/eu/timepit/refined/api/RefinedType.scala @@ -10,13 +10,13 @@ trait RefinedType[FTP] { val validate: Validate[T, P] - val subst1: F[T, P] =:= FTP + val alias: F[T, P] =:= FTP - val subst2: FTP =:= F[T, P] + val unalias: FTP =:= F[T, P] def refine(t: T): Either[String, FTP] = { val res = validate.validate(t) - if (res.isPassed) Right(subst1(refType.unsafeWrap(t))) + if (res.isPassed) Right(wrapUnsafe(t)) else Left(validate.showResult(t, res)) } @@ -29,7 +29,10 @@ trait RefinedType[FTP] { ): FTP = macro macros.RefineMacro.refineImpl[FTP, T, P] def unwrap(tp: FTP): T = - refType.unwrap(subst2(tp)) + refType.unwrap(unalias(tp)) + + def wrapUnsafe(t: T): FTP = + alias(refType.unsafeWrap(t)) } object RefinedType { @@ -57,7 +60,7 @@ object RefinedType { override val refType: RefType[F] = rt override val validate: Validate[T, P] = v - override val subst1: F[T, P] =:= F0[T, P0] = implicitly - override val subst2: F0[T0, P0] =:= F[T, P] = implicitly + override val alias: F[T, P] =:= F0[T, P0] = implicitly + override val unalias: F0[T0, P0] =:= F[T, P] = implicitly } }