Value Classes in Scala | Rock the JVM

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 19

  • @luismiguelmejiasuarez2020
    @luismiguelmejiasuarez2020 3 года назад +4

    Great video as always! - Just one minor note, using a case class for a newtype is a bad idea because of copy. So you can have BarCode(1-12345-12345).map(_.copy(code = "Whatever")) and now you have a faulty BarCode.

  • @aethermass
    @aethermass 3 года назад +2

    Thanks for taking us all the way to opaque types. I have been using value classes for a while without noticing issues but opaque types looks to be an improvement. Hopefully, having dependencies of Spark and Akka won't delay me from moving to Scala 3 for too long. I might separate out the Spark module if they take a long time.

    • @rockthejvm
      @rockthejvm  3 года назад +1

      Nice, glad to hear you found value in these!

    • @MirrorsEdgeGamer01
      @MirrorsEdgeGamer01 3 года назад

      @@rockthejvm
      Excuse the pun. Great video thank you.

  • @jimaaman
    @jimaaman 3 года назад +1

    Interesting! Thanks for the alternative to supertagged. The `@newtype` annotation seems like a much cleaner way to define the types.

  • @woutermenninga8524
    @woutermenninga8524 Год назад

    Question about 20:50: this code actually does compile for me: I can assign any string to "val barcode: BarCode =". Was this changed for the release version of Scala 3?

  • @hafizullahqasemi7332
    @hafizullahqasemi7332 2 года назад +1

    great content as always !

  • @robert33232
    @robert33232 Год назад +1

    Thanks you for the video! :-))

  • @patriciogorin1375
    @patriciogorin1375 3 года назад +1

    Great video again, thank you!
    I have a question. I've been using refined types to accomplish this type of strong modeling. Is there a relationship between value classes or new opaque types? Again, thank you!

    • @rockthejvm
      @rockthejvm  3 года назад +1

      Glad you liked it!
      Value classes, newtypes and opaque types are different approaches to the same problem of "hiding" a piece of information (like a string) behind a completely new type that MEANS something in particular for you.

  • @HoD999x
    @HoD999x 2 года назад

    question about 17:56 - you're createing an either every time. why don't you count this as runtime overhead?

    • @rockthejvm
      @rockthejvm  2 года назад

      You have to create some sort of error case, which would have happened anyway. It's the wrapper class that eliminates the runtime overhead.

  • @frankhofmann9089
    @frankhofmann9089 3 года назад +1

    What editor/IDE are you using?

    • @rockthejvm
      @rockthejvm  3 года назад +1

      Intellij + Scala plugin:
      jetbrains.com/idea
      (not affiliated in any way, I just like the tool)

  • @JulienBertozzi
    @JulienBertozzi 3 года назад

    Thank you for your videos!

  • @Sleight94
    @Sleight94 3 года назад +2

    Luckily the macro plugin is not needed anymore in 2.13