Skip to content

Instantly share code, notes, and snippets.

@joshlemer
Created April 24, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshlemer/595ac89365ec6e7c24f73f3c57a9dc64 to your computer and use it in GitHub Desktop.
Save joshlemer/595ac89365ec6e7c24f73f3c57a9dc64 to your computer and use it in GitHub Desktop.
Conference Stuff

What’s new in 2.13

Release Notes https://github.com/scala/scala/releases/tag/v2.13.0-M1 https://github.com/scala/scala/releases/tag/v2.13.0-M2 https://github.com/scala/scala/releases/tag/v2.13.0-M3 https://github.com/scala/scala/releases/tag/v2.13.0-M4 https://github.com/scala/scala/releases/tag/v2.13.0-M5 https://github.com/scala/scala/releases/tag/v2.13.0-RC1

Selected Points: * What is the new arch of the collections * Goals * Simplify the api for users No more CanBuildFrom Inheritance tree is greatly simplified: * no need to abstract parallel/sequential collections means no more GenTraversableOnce etc to abstract over * views are separate, further simplifying the inheritance hierarchy * better separation of mutable and immutable collections, most "immutable" operations on mutable collections are deprecated

        * Simplify api for implementors
            * Default implementations of all traits/classes should be correct, even for potentially lazy collections
            ... show example of implementing a custom Seq...
            * no more CanBuildFrom greatly simplifies implementation and comprehesibility of code
        * Performance
    * CanBuildFrom
        Previously
            def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That
        Now
            def map[B](f: A => B): C[B]
        Was originally used to statically change behavior of transformations on collections with “specialized” element types like BitSet with Ints, or Maps with (K, V)’s, or TreeSet’s with T: Ordering, or String with T <: Char, or Array with T: ClassTag
        Now, this logic is expressed with simple method overloads which are possible in 2.12+
        ```scala
        val s: BitSet = ...

        // Scala 2.11 and earlier would have required:
        val c1 = s.map((i: Int) => i+1)

        // This works in 2.12+:
        val c2 = s.map(i => i+1)
        ```

        Other uses of `CanBuildFrom` included changing the return type of a transformation without intermediate steps:

        ```scala
          val v: Vector[Int] = List(1).map(_ + 1)(scala.collection.breakOut)
        ```

        now, it is recommended to use `.iterator` or `.view`, transform, and then `to(Target)`

        ```scala
        val v0: Vector[Int] = List(1).iterator.map(_ + 1).to(Vector)
        val v0: Vector[Int] = List(1).view.map(_ + 1).to(Vector)
        ```

    * `from` and `to`
        ...show definition of from and to...

        previously was 
        ```scala
            def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A]]): Col[A]
        ```

        * has the advantage of accommodating collections of type M[_, _], `C[_]` or `C`, 
        * allows "evidence factories" to convert to proper factories
        * easy to do performance optimization in the factory 


    * Each View previously extended the collection it was a view of. Now, Views are a separate type of Iterable entirely
    * Traversable is no longer root of collections, instead IterableOnce which can always produce at least one Iterator (it might itself be the iterator)
    * Parallel collections no longer in core stdlib, now exist as separate artifact, and parallel collections are in a totally different branch extending from IterableOnce. Sequential collections no longer inherit “Gen…” traits 

Singleton literal types
    ... find more useful examples...
    ```scala
    val one: 1 = 1

    val hello: String = valueOf["hello"]

    def takesOnlySingletons[T <: Int with Singleton](value: T): Unit = ???
    ```

Specific Performance Improvements Vectors Small vectors VectorBuilder shares structure HashMaps/HashSets Mutating builder Shallow Mutation Sharing hashcodes New encoding: CHAMP vs HAMP

Specific new things IterableOnce ... Insert Definition here... util.Using ... Insert some usage examples here... productNames ... insert some usage examples here...

    ```scala
    case class User(id: Long, name: String, age: Int)

    User(1L, "abc", 100).productNames.toList // List("id", "name", "age")
    ```

immutable.ArraySeq
immutable.LazyList
    ... insert some usage examples here...
immutable.SeqMap
    ... insert some usage examples here...
    * TreeSeqMap
    * VectorMap
    ListMap (not new, but implements this new trait)
Java interop for Duration, Functions, Futures, Optionals, Streams
    ... insert some usage examples here
mutable.ArrayDeque
    ... talk about structure / performance difference here...
Option.when/unless
    ```scala
    val x: Option[String] = Option.when(1 > 0) {
      "here"
    }

    assert(x == Some("here"))

    val y: Option[String] = Option.unless(1 > 0) {
      "here"
    }

    assert(y == None)
    ```

Deprecated Things immutable.Stream mutable.ListMap mutable.ListSet concurrent.{Channel,DelayedLazyVal,JavaConversions,SyncChannel,SyncVar} scala.collection.JavaConverters => scala.jdk.CollectionConverters.Ops._ Procedure syntax (def m() { ... }) is deprecated #6325 View bound syntax (A <% B) is deprecated #6500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment