-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derive a custom Validate from an existing one #397
Comments
@hseeberger Asking questions here is fine. The Gitter channel would be another option. You're right, currently there is no API to scala> implicit val finiteDurationValidate = Validate.fromPredicate(
(d: FiniteDuration) => d.length > 0,
(d: FiniteDuration) => s"$d is positive",
Greater(shapeless.nat._0))
scala> refineV[Positive](1.minute)
res32: Either[String, Refined[FiniteDuration, Positive]] = Right(1 minute)
scala> refineV[Positive](-1.minute)
res33: Either[String, Refined[FiniteDuration, Positive]] = Left(Predicate failed: -1 minutes is positive.) I think we should definitely make it easier to define this instance via the |
Thanks for the quick answer! I have changed the title (removed "question") to better reflect the new nature of this issue (now a feature requirement). |
I've been thinking about this too – we have Another (more verbose) alternative I just discovered a few days ago is to use |
Making |
Is there support for # git clone refined
$cd refined
$ggrep -r FiniteDuration .
$ggrep -r Duration .
$ Thanks for your help and this great library! |
@kevinmeredith refined does not (yet) provide support for refining |
For deriving a custom final class Equivalence[A, B]
private val equivalenceInstance = new Equivalence[Any, Any]
type `<==>`[A, B] = Equivalence[A, B]
implicit def inferEquivalence[T,A,B](implicit eab: A ==> B, eba: B ==> A) : A <==> B =
equivalenceInstance.asInstanceOf[A <==> B] And then we want to have the following validation inference rule: implicit def equivalenceValidation[T, A, B](implicit v: Validate[T, A], e : A <==> B): Validate[T, B] =
v.asInstanceOf[Validate[T, B]] |
First let me apologize for creating an issue for a simple question, but I haven't found another channel.
So, let's say I would like to refine
scala.concurrent.duration.FiniteDuration
, e.g. withPositive
. My first idea was to simply usePositive
and (contra)map it over a function extracting thelength
from theFiniteDuration
which is aLong
. But I haven't found a way to do that, i.e. no public (contra)map method onValidate
.Any help would be highly appreciated.
The text was updated successfully, but these errors were encountered: