Intro to Scala

James Ward ~ @_JamesWard

Get Started with Typesafe Activator

  1. Download Activator:
  2. Extract & launch Activator:
    activator new
    (or launch the UI from your file browser)
  3. Create a new app with the Hello, Scala template

Run the app once:

activator run

Run the app continuously:

activator ~run

Launch the Scala REPL:

activator console

Run the tests continuously:

activator ~test


Non-side-effecting and concurrency friendly

val foo: String = "asdf"

Type Inference

Type Safety with less Typing

val foo = "asdf"
val listOfInt: List[Int] = List(1,2,3)

Case Classes

Value Objects Done Right

case class Foo(name: String)
  • Concise Syntax
  • Built-in toString, equals, hash-code, extractor, creator, copy
val foo = Foo("asdf")
val foo1 = Foo.apply("asdf")
val foo2 = new Foo("asdf")
val bar = foo.copy("zxvc")

Optional Values

Say Goodbye to Null Pointer Exceptions

val asdf: Option[String] = Some("asdf")
val notta: Option[String] = None

Higher Order Functions

Functions are a thing

def stringLength(s: String): Int = s.length

Functions can take other functions as params

def stringTransformer(s: String, f: String => Int): Int = f(s)

The map() function transforms each item in a container


Anonymous functions

List("a","bb","ccc").map(s => s.length)

Learn More