scala session

  • Concurrency
  • DSL
  • Pattern matching
  • ADTs (Algebric Data Types)
  • Lambdas
  • Immutability
  • Contextual parameters

  • flow dsl

Principles 1.

Misc

  1. implicit overloaded for
    1. exetension methods
    2. type classes
    3. implicit parameters
    4. implicit conversions

Why scala changing so fast?

  • Inspirations from different languages.

  • Opinionated language? So many ways of doings things?

frameworks

Misc

cs

  • cs launch scala:3.3.0

sbt

  • sbt new <template>

Collections

List

  • list.span
  • :: cons operator
  • ::: concat operator

enum

  • lists are created using sharing references of previous list.
  • Structural sharing.
  • Consists of two parts
    • head
    • cons
  • compute length

Why not lazy evaluation.

  • memory profile prediction is hard for application

Custom list

enum Lst[+T]:
    case Empty
    case Cons[T](head: T, tail: Lst[T])
sealed trait Lst[+T]
object Lst:
    case object Empty extends Lst[Nothing]
    case Cons[T](head: T, tail: Lst[T]) extends Lst[T]
  • GJ generic java

  • class cast exception

todo

  1. animal super class
    1. dog and cat sub class
  2. make list of dogs and animals
  3. make an array of dogs and animals.
  4. Try to add cat in the list of animals.
  5. Try to add cat in the array of animals.