Scala Tutorial

Philipp Haller | @philippkhaller

This presentation is executable.

Clone and run: http://git.io/XDbxpw

Brought to you by and

What is Scala?

History

Adoption

According to StackOverflow and GitHub Scala is used a lot.

Momentum

Philosophy

First Example

Java

Scala

Using arrays in...

... Java:

... and in Scala:

Scala Basics

Running Scala

Essentials

Primitives

Complex numbers

Everything is an expression

Expression examples

What about println?

Scala's REPL

REPL Commands

Documentation

Basics: Arrays

Command-Line Tools

Scala Applications

The main Method

Recursive Functions

Example: computing the Fibonacci series

Task: write a recursive function that computes the n-th Fibonacci number:

Lists

Lists: Basics

Classes and traits

Classes

Classes

When compiled, this class will look and behave exactly like the obvious translation to a Java class. No glue code necessary.

Primary Constructor

Example

Constructor parameters and fields

Auxiliary Constructors

Traits

Exercise: Traits

Example

Functional Programming

What is FP?

Scala as a Functional Programming Language

Function literals

Equivalent forms

Higher-Order Functions

Higher-Order Functions: Examples

Collections

Examples

Tuples

Example: Maps

Example

Example: Solution

Everything is an object

Syntactic Sugar

Function Subtypes

For-comprehensions

For-comprehensions

Unit Testing

Building and Testing

Testing with ScalaTest

ScalaCheck: Property-based testing

Pattern matching

Pattern matching

Open-Source Ecosystem

Scala Open Source Project

Scala modules

Thanks!

Questions!

#

/