Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala 3 - A Quick Tour - Scala Italy 2021

Scala 3 - A Quick Tour - Scala Italy 2021

E99b07644586e9e1723757bf8e34ea68?s=128

Daniela Sfregola

October 23, 2021
Tweet

Transcript

  1. Scala 3 A Quick Tour @DanielaSfregola Scala Italy - October

    2021
  2. Hellooooo • Software Engineer 
 living in London UK •

    Scala Lover ❤ • OS Maintainer • Author of 
 "Get Programming with Scala" by Manning
 
 35% OFF on EVERYTHING
 with code "ctwscalait21"
  3. Scala 3 is here! • After 8 years of work

    • 28,000 commits • 7,400 pull requests • 4,100 closed issues • ...released on May 13th, 2021! https://www.scala-lang.org/blog/2021/05/14/scala3-is-here.html
  4. An overview • https://dotty.ep fl .ch/docs/reference/overview.html

  5. @main Annotation object HelloWorld extends App { println("Hello World!" )

    }
  6. @main Annotation object HelloWorld extends App { println("Hello World!" )

    } object HelloWorld { @main def hello: Unit = { println("Hello world!" ) } }
  7. @main Annotation object HelloWorld extends App { println("Hello World!" )

    } object HelloWorld { @main def hello: Unit = { println("Hello world!" ) } } object Hello { @main def echo(n: Int, word: String): Unit = { println(word * n ) } }
  8. Parametrized Traits trait Nameable { def name: Strin g }

  9. Parametrized Traits trait Nameable { def name: Strin g }

    trait Nameable(name: String)
  10. Intersection Types class A class B def foo: A &

    B = ???
  11. Union Types class A class B def foo: A |

    B = ???
  12. Package Object // in file my/demo/package.scal a package m y

    package object demo { def customLog(msg: String) { println(s"Customised package log: $msg" ) } }
  13. Package Object // in file my/demo/package.scal a package m y

    package object demo { def customLog(msg: String) { println(s"Customised package log: $msg" ) } } [ DROPPED ]
  14. Enums sealed abstract class Color(val rgb: Int)
 case object Red

    extends Color(0xFF0000 ) case object Green extends Color(0x00FF00 ) case object Blue extends Color(0x0000FF)
  15. Enums sealed abstract class Color(val rgb: Int)
 case object Red

    extends Color(0xFF0000 ) case object Green extends Color(0x00FF00 ) case object Blue extends Color(0x0000FF) enum Color(val rgb: Int) : case Red extends Color(0xFF0000 ) case Green extends Color(0x00FF00 ) case Blue extends Color(0x0000FF)
  16. Improved Type Inference Map("Scala" -> 3).map { (k, v) =>

    s"$k$v" }
  17. Improved Type Inference Map("Scala" -> 3).map { (k, v) =>

    s"$k$v" } Scala 2.13.4
  18. Improved Type Inference Map("Scala" -> 3).map { (k, v) =>

    s"$k$v" } Scala 2.13.4
  19. Improved Type Inference Map("Scala" -> 3).map { (k, v) =>

    s"$k$v" } Scala 3.0.0
  20. Improved Type Inference Map("Scala" -> 3).map { (k, v) =>

    s"$k$v" } Scala 3.0.0 Scala 2.13.4
  21. Procedure Syntax def echo(str: String) { st r }

  22. Procedure Syntax def echo(str: String) { st r } Scala

    2.13.4
  23. Procedure Syntax def echo(str: String) { st r } Scala

    2.13.4
  24. Procedure Syntax def echo(str: String) { st r } Scala

    3
  25. Procedure Syntax def echo(str: String) { st r } Scala

    3
  26. Improved Error Messages Arrested Developers What the Scala Compiler &

    Lucille Bluth 
 Have In Common by Fiona Condon, NeScala 2017 https://www.youtube.com/watch?v=78iIbiRwFTM
  27. Improved Error Messages def echo(str: String): Unit = { st

    r } def echoTwice(str: String): String = { echo(str) match { case x: String => s"$x$x " } }
  28. Improved Error Messages Scala 2.13.4

  29. Improved Error Messages Scala 2.13.4 Scala 3

  30. Strict Equality List("Scala", "3").headOption == "Scala"

  31. Strict Equality List("Scala", "3").headOption == "Scala" Scala 2.13.4

  32. Strict Equality List("Scala", "3").headOption == "Scala" Scala 2.13.4 Scala 3

  33. Compatibility with 2.13 Migrating to Scala 3 is easy* !

    * if you are using Scala 2.13 * if you don't have macros in your code Scala 3 Migration Guide https://docs.scala-lang.org/scala3/guides/migration
  34. Thank You! •Twitter: @DanielaSfregola •"Get Programming with Scala" 
 by

    Manning
 
 35% OFF on EVERYTHING 
 with code "ctwscalait21"