Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
@ugobourdon
@ubourdon
I was thinking that using refined type produce the validator for me no ?
this val i1: Int Refined Positive = 5 works fine
but refineMV[Int Refined Positive](5) do not.
Matheus Hoffmann
@Hoffmannxd
@ubourdon I had the same problem, for what i get when using refineV[T] or refineMV[T] T must be the predicate, not the refined type itself.
@ugobourdon
@ubourdon
ha
:D
thx
you save me for hours to not see this :D
@ugobourdon
@ubourdon
But :D
When i try this
def build[Size](s: String): Either[String,NonEmptyStringMaxSize[Size]] = refineV[NonEmptyStringMaxSizePredicate[Size]](s)
i have again this error message :
could not find implicit value for parameter v: eu.timepit.refined.api.Validate[String,domain.common.string.TestNonEmptyStringMaxSize.NonEmptyStringMaxSizePredicate[Size]]
with type NonEmptyStringMaxSizePredicate[Size] = And[NonEmpty, MaxSize[Size]]
@ugobourdon
@ubourdon
i find
i don't precise the Size parameter
Gabriel Volpe
@gvolpe
Hi all, say I have the following refinement type:
type MyPred = Long Refined Size[16]
The only way to create a Refined type without validating it passes is by using Refined.unsafeApply[Long, Size[16]?
It is for testing purposes where I'm obtaining values from Scalacheck generators
Frank S. Thomas
@fthomas
@gvolpe Yeah, that's correct. I guess, in a lot of cases the type parameters can be inferred, so there's probably no need to specify them. If you have a "companion" for MyPred, you could also use MyPred.unsafeFrom which returns a MyPred but throws if validation fails.
Gabriel Volpe
@gvolpe
Thanks @fthomas !
Gabriel Volpe
@gvolpe
Is there any way to get a compile-time error? Sth like:
type ValidFiniteDuration = FiniteDuration Refined Positive

10.minutes: ValidFiniteDuration // compiles
-4.seconds : ValidFiniteDuration // doesn't compile
Gabriel Volpe
@gvolpe
I guess I should be looking at this issue? :) https://github.com/fthomas/refined/issues/633#issuecomment-488071074
Frank S. Thomas
@fthomas
@gvolpe It is not possible right now without changing the current RefineMacro because 10.minutes is not a Literal(Constant(...)) in Scala's AST. This comment contains some of my thoughts about "literals" like 10.minutes. I'd like to support this in the future but doing so with the current macros seems like a dead end to me.
Gabriel Volpe
@gvolpe
Oh that makes sense, thanks for the clarification @fthomas.
matfournier
@matfournier
Hey. I'm in a custom Validate[T, R] method and I'm stuck holding a Either[String, ThingThatIWant] but I'm not sure how to convert that into the Res type that validate expects
use case: I take in 3 strings and 1 Option[String] and I need to validate that all strings exist and are nonEmpty, so I've written a implicit val vv:Validate[(String, String, String, Option[String]), ValidAuthorizeRequest]
matfournier
@matfournier
I guess I don't understand the Result[A] type
matfournier
@matfournier
Ideally I'd like torefineV[ThingIWant](myInput) but this transform step is messing with me.
Zhenhao Li
@Zhen-hao
I don't know if it is the right place to ask because I am using slick-refined.
but I got compiling error on val query = users.filter(u => u.email.toString == u.email.toString):
inferred type arguments [Boolean] do not conform to method filter's type parameter bounds [T <: slick.lifted.Rep[_]]scalac
same if I use ===
val query = users.filter(u => u.email === u.email)
this one compiles
in both cases, the type is just User => Bool. why is the compiler looking for anything else?
Frank S. Thomas
@fthomas
@matfournier I don't get what you are trying to do. Is the code somewhere where I can have a look what you have so far?
@Zhen-hao I don't know aynthing about slick, so I can't help you with that problem.
Zhenhao Li
@Zhen-hao
thank you @fthomas. I created an issue on the slick-refined repo
Zhenhao Li
@Zhen-hao
is refineV deprecated? is it the same as RefType.applyRef?
Zhenhao Li
@Zhen-hao
is there a way to express "T is a singleton type"?
Zhenhao Li
@Zhen-hao
  val ten: Int Refined Positive = 10 
  val witSingleton = implicitly[WitnessAs[ten.type, Int]]
why does this one give me could not find implicit value for parameter e: eu.timepit.refined.internal.WitnessAs[com.nt.package.ten.type,Int]scalac?
did I misunderstood WitnessAs? @fthomas
matfournier
@matfournier
@fthomas putting together a gist now
Gabriel Volpe
@gvolpe
@matfournier you can normally get away by writing the instance using Validate.fromPredicate but I'm sure Frank will give you a better answer
matfournier
@matfournier
@gvolpe Will look into that. Not sure how to do Option unpacking part (e.g. validate that the optional thing is Some(string) && unpack it && make sure the string is nonEmpty)
Frank S. Thomas
@fthomas
@matfournier I see the problem now. Validate[T, P] is intended to check that a type T is valid according to the predicate P. If it is valid, the library tags the type with the predicate P like this: T Refined P. So the library has Validate instances like Validate[String, NonEmpty] to support the refinement type String Refined NonEmpty. It is not intended to map T to P like you do in your gist. Your Validate instance would support a refinement type like (String, String, String, Option[String]) Refined ValidAuthorizeRequest but that is not what you're trying to achieve here
matfournier
@matfournier
Ah. I guess there is no way to validate and transform? Those pesky Options are always a problem (thanks protobuf generated types)
The rest makes sense! Thank you