Refined Types in Scala | Rock the JVM

  Рет қаралды 3,660

Rock the JVM

Rock the JVM

Күн бұрын

Пікірлер: 17
@hoangnhatpham8076
@hoangnhatpham8076 4 жыл бұрын
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.
@rockthejvm
@rockthejvm 4 жыл бұрын
will do!
@jli8000
@jli8000 3 жыл бұрын
@@rockthejvm a..zzzzzz--。zzZzzzzz-Z
@jli8000
@jli8000 3 жыл бұрын
@@rockthejvm z.
@luismiguelmejiasuarez2020
@luismiguelmejiasuarez2020 4 жыл бұрын
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.
@rockthejvm
@rockthejvm 4 жыл бұрын
That's a nice note, thank you - I will also release a new version of this video when Scala 3 comes out.
@lobovutare
@lobovutare 4 жыл бұрын
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.
@rockthejvm
@rockthejvm 4 жыл бұрын
Yep, there's a compile time tradeoff there for sure. Have you seen the opaque types video?
@RomanArkharov
@RomanArkharov 4 жыл бұрын
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?
@rockthejvm
@rockthejvm 4 жыл бұрын
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.
@MercedeX7
@MercedeX7 3 жыл бұрын
@@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.
@mourikogoro9709
@mourikogoro9709 4 жыл бұрын
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?
@rockthejvm
@rockthejvm 4 жыл бұрын
Not that I know of - I might create a video on it
@nitintharwani
@nitintharwani 4 жыл бұрын
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)
@rockthejvm
@rockthejvm 4 жыл бұрын
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
@nitintharwani
@nitintharwani 4 жыл бұрын
Is there any other way to achieve this check at compile time?
How to Deploy Scala Code to AWS Lambda - a Tutorial | Rock the JVM
10:10
Self-Types in Scala - the Why and the How | Rock the JVM
14:57
Rock the JVM
Рет қаралды 8 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН
GIANT Gummy Worm #shorts
0:42
Mr DegrEE
Рет қаралды 152 МЛН
Scala 3: Opaque Types | Rock the JVM
18:15
Rock the JVM
Рет қаралды 6 М.
Idiomatic Error Handling in Scala | Rock the JVM
26:45
Rock the JVM
Рет қаралды 9 М.
Given and Using Clauses in Scala 3 | Rock the JVM
20:24
Rock the JVM
Рет қаралды 6 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 192 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 846 М.
Andrew Kelley   Practical Data Oriented Design (DoD)
46:40
ChimiChanga
Рет қаралды 153 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 158 М.
Type Lambdas in Scala 3 | Rock the JVM
18:07
Rock the JVM
Рет қаралды 7 М.
I Sent a Subscriber to Disneyland
0:27
MrBeast
Рет қаралды 104 МЛН