Refined types are magical. Please also make a video on how these things work under the hood. I'm sure it will be very interesting.
@rockthejvm4 жыл бұрын
will do!
@jli80003 жыл бұрын
@@rockthejvm a..zzzzzz--。zzZzzzzz-Z
@jli80003 жыл бұрын
@@rockthejvm z.
@luismiguelmejiasuarez20204 жыл бұрын
Great video! Just one minor note, it would have been good to mention than since Scala 2.13 it is no longer needed to use the Witness, since now we can use literal types directly in the source code. It would also have been interesting to explain that Scala has this concept of literal types and that is what refined uses, so when we say Less[100] we meant the literal type 100 that has only one valid value the literal 100, and that even if that concept has existed in the compiler since ages, it was not possible to express (until 2.13), so Shapeless provided Witness to extract such types.
@rockthejvm4 жыл бұрын
That's a nice note, thank you - I will also release a new version of this video when Scala 3 comes out.
@lobovutare4 жыл бұрын
I love this type magic. Unfortunately I used refined once in a project and had such a significant drop in my compile time (from a few seconds to almost a minute on a small project) that I chose to drop refined all together. I think I will just stick with opaque types when moving to Scala 3.
@rockthejvm4 жыл бұрын
Yep, there's a compile time tradeoff there for sure. Have you seen the opaque types video?
@RomanArkharov4 жыл бұрын
Hey, Daniel. Thank you for the video. For me, the idea to check values at compile time looks strange. At least in my practice, in most cases, I write programs that manipulates with user input and in such case I can't use compile time checks. For runtime checks for me it looks more simple to use code like the following rather than use some additional libraries: case class User(name: String, email: String) { require(name.nonEmpty && name.charAt(0) == name.charAt(0).toUpper, "Name must start from capital letter") require(email.nonEmpty && """[a-z0-9]+@[a-z0-9]+\.[a-z]{2,}""".r.findFirstMatchIn(email.toLowerCase).isDefined, "Email is invalid") } Could you please show some examples where refind types in runtime are more useful or reliable than the code above? And could you please show some more advanced real-world examples where compile-time checks might be useful?
@rockthejvm4 жыл бұрын
Yep - will do some more stuff around this. The idea with refined types is that certain properties are known to be true at compile time, so you can safely process them without needing to do asserts all the time.
@MercedeX73 жыл бұрын
@@rockthejvm how this is possible if you are processing the data that simply isn't available at compile time. Most of data our apps process is either "created" or "fed into" our apps.
@mourikogoro97094 жыл бұрын
I find myself take a lot of time looking for potential bugs there. So far, I debug my codes without any debugger feature in VSCode and I think I should learn the debugger but I can't find a good tutorial (for Scala). Any suggestion?
@rockthejvm4 жыл бұрын
Not that I know of - I might create a video on it
@nitintharwani4 жыл бұрын
Hi, Is there way to check unique constraint across objects using refined, For e.g. case class Job(name:String, properties:Map[String,String]) First Correct case => should not give compilation error val job1 = Job("xyz",Map("xyz" -> "xyz")) val job2 = Job("abc",Map("abc" -> "abc")) val listJobs = List(job1,job2) Second InCorrect => case should give compilation error while creating list val job1 = Job("xyz",Map("xyz" -> "xyz")) val job2 = Job("xyz",Map("abc" -> "abc")) val listJobs = List(job1,job2)
@rockthejvm4 жыл бұрын
I don't think it supports what you're asking for, but you can check here for supported predicates: github.com/fthomas/refined#provided-predicates
@nitintharwani4 жыл бұрын
Is there any other way to achieve this check at compile time?