What is Scala?

  • Functional/OO multiparadigm language

  • Statically and strongly typed

  • Runs on the JVM (Java)

  • Combines elements of languages like Haskell, OCaml, Java, Erlang

  • Killer features:

    • Higher order functions, first class functions (e.g. 'map', 'flatMap

    • 'case class'es - i.e. data classes

    • pattern matching

    • emphasis on immutability

Installation

  • Only need a few things to be productive:
    • 'sbt' - scala's build tool
      • Think: maven, gradle, npm, leiningen
      • OS X: `brew install sbt`
    • JDK8+ - Scala runs on the JVM
    • Text editor or IntelliJ IDEA

sbt tasks

  • Important tasks
    • 'clean' - removes compiled .class files and other artifacts in target/ folder, akin to clearing cache
    • 'compile' - compiles your project
    • 'test' - runs tests
    • 'run' - runs your code if it can find a main
  • Prefixing '~' to tasks will place a continuous watch on the project and will re-execute on writes (~compile will recompile the whole project on file saves)

Typical Project Structure

  • src/main/scala/... - source code
  • build.sbt - Build file (like package.json)
  • target/ - generated classes, artifacts, jars, etc
  • project/build.properties - sets sbt version
  • project/plugins.sbt - sbt plugins

(can be divided into subprojects, more on that in the future)

Light Intro to Some(Scala Features)

  • 'Container' types and what they represent
    • Option - a value or lack thereof
    • Try - a value or failure wrapped over exception
    • Future - async value or failure wraped over exception
  • Case classes - data classes with default immutable fields, pattern matching
  • Higher order functions - e.g. List.map
  • For-comprehensions
Made with Slides.com