What's New with Scala?
Karl Bielefeldt
2.13 Collections
- More consistency between lazy and strict collections.
- Simpler object hierarchy.
- No more signatures like
map[B, That](f: Int => B)(implicit bf: CanBuildFrom[List[Int], B, That])
- New more efficient
groupMap
that combines groupBy
followed by mapValues
- New
LazyList
instead of Stream
, both head and tail are lazy.
- 2.13.0-M4 was released the middle of May
- 2.13.0-M5 is planned for August 10th
- What's taking so long?
- What can I do to help?
Tooling Improvements
- Language Server Protocol
- Build Server Protocol/Bloop
- Triplequote Hydra parallel compiler
- Scala Native
GraalVM
- Multi-language
- Native images
- NBI is 22M including runtime.
- Compare to 55M for jars and ~200M for the jre, + OS for docker container.
Consistency
- Intersection types
A & B
replacing A with B
. Commutative!
- Implicit function types
implicit A => B
- Dependent function types
(x: T) => x.S
- Traits can have parameters
trait T(x: S)
- Can have tuples longer than 22.
- Macros based on TASTY, a more consistent interface not tied directly to compiler internals.
Safety
- Union Types
A | B
- Mutiversal equality. Equality checks only make sense for compatible types.
- Restricted implicit conversions, with simpler syntax.
- Null safety. Must explicitly declare a sum type:
String | Null
.
- Effect Capabilities. Must declare effects such as null pointer exception being throwable.
- Multiple levels of macros, not everything is super-powerful whitebox.
Ergonomics
- Enums
enum Color {case Red, Green, Blue}
- Type lambdas
[X] => C[X]
.
- Extension clauses:
extension StringOps for String { ... }
Performance
- Opaque types:
opaque type Id = String
- Can declare parameters as erased, i.e. only used during type checking.