-
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
Size predicate validator error #1155
Comments
Try |
Validator is still missing. I also tried to rewrite self-written validator with implicit def validateSizeN[N <: Int, R](implicit
w: ValueOf[N]
): Validate.Plain[R, Size[Equal[N]]] =
Validate.fromPredicate[R, Size[Equal[N]]](
_.toString.length == w.value,
_ => s"Must have ${w.value} digits",
Size[Equal[N]](Equal[N](w.value))
) |
Right. You're trying to check if the string representation of an
Looks like https://github.com/fthomas/refined/blob/master/modules/docs/macro_pitfalls.md. Custom predicates + macros probably won't work in Scastie. |
They are not working in the IDEA either. Tried to write exact types instead type aliases and it helped. Thanks for helping out! I didn't really got what it is about in macro_pitfalls. I should replace my |
My recommendation is to not use refined's macros at all. They cause problems like above and are not available on Scala 3.
No, the alias is fine. If you don't use macros, there is also no need to move the What I've been doing lately is to define a type alias + an object with the same name that extends import eu.timepit.refined.api.RefinedTypeOps
type SixP = Int Refined Size[6]
object SixP extends RefinedTypeOps[Int Refined Size[6], Int] which gives you nice syntax for creating |
Got it, thanks for clarifying! |
There is already a |
Lib version: "0.10.1"
There is no validator for types refined with
Size[n]
predicate. Which leads to an error:In "Practical FP in Scala" book there is this workaround (
SizeValidator
on the code), but it doesn't work for me anyway with error:Here is scastie runnable example: https://scastie.scala-lang.org/frNAMizRRpaTBaoeJjjrEQ
The text was updated successfully, but these errors were encountered: