SlideShare a Scribd company logo
SCALA
QUICK INTRODUCTION
d.jureczko@gmail.com
@DamianJureczko
AGENDA
A little bit about Scala
Basic syntax
Object-oriented Scala
Functional Scala
Live code
SCALA
General purpose programming language
Multiparadigm: object-oriented & functional
Statically typed
Runs on the JVM
Created by Martin Odersky
First release in 2004
GET STARTED WITH SCALA
Binaries
scala-lang.org/download
SBT
scala-sbt.org/download
IDE
Scala IDE (Eclipse), IntelliJ, NetBeans
SBT
A build tool for Scala, Java and more
scala-sbt.org
FIRST APP
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, World!")
}
}
BASIC SYNTAX
val name: String = "John"
var age: Int = 30
i = 31
def add(x: Int, y: Int): Int = {
x + y
}
STRING INTERPOLATION
val name: String = "John"
println(s"Hello $name")
MULTILINE STRINGS
val text: String =
"""
|This text spans
|multiple lines.
""".stripMargin
STATICALLY TYPED LANGUAGE
var name: String = "John"
name = "Mark"
name = 2 // compilation error !!!
def add(x: Int, y: Int): Int = x + y
add(1, "two") // compilation error !!!
TYPE INFERENCE
val name = "John"
val age = 30
def add(x: Int, y: Int): Int = x + y
val sum = add(1, 2)
OBJECT-ORIENTED SCALA
Everything is an object
val x = 10
x.toString
CLASSES
abstract class Vehicle {
def move(): Unit
}
class Car extends Vehicle {
override def move(): Unit = {
println("driving")
}
}
TRAITS
trait Diving {
val deep = 100
def dive(): String = s"diving $deep meters"
}
class Car extends Vehicle with Diving {
override val deep = 200
override def move(): Unit = {
println(dive())
}
}
OBJECTS
object SeeDiving {
val MaxDepth = 500
def pressure(depth: Int): Double = depth / 10 * 0.99
}
class Car extends Vehicle with Diving {
override val deep: Int = SeeDiving.MaxDepth
override def move(): Unit = {
println(dive() + s" with ${SeeDiving.pressure(deep)} atm")
}
}
CASE CLASSES
// declare
case class User(email: String, password: String)
// create
val admin = User("admin@company.com", "buddy")
// access fields
val adminEmail = admin.email
// create copy
val otherAdmin = admin.copy(email = "admin2@company.com")
// compare
assert(admin != otherAdmin)
PATTERN MATCHING
val result = something match {
case "value" => "it's String equal to 'value'"
case 10 => "it's Int equal to 10"
case s: String => "it's String with value: " + s
case _ => "it's something else"
}
PATTERN MATCHING AND CASE CLASSES
val result = user match {
case User("admin@company.com", "buddy") =>
"it's administrator"
case User(email, password) =>
"it's " + email + ", his password is: " + password
}
FUNCTIONAL SCALA
FUNCTIONAL PROGRAMMING
Pure functions
No side effects
FIRST-CLASS FUNCTIONS
Function is a first-class citizen
Can be assigned to a variable
Can be passed as an argument of a function
Can be returned from a function
HIGH-ORDER FUNCTIONS
Take other functions as an argument
Return functions as a result
SCALA FUNCTIONS
// function type
(Int, Int) => Int
// anonymous function
(x: Int, y: Int) => x + y
ASSIGNING FUNCTION TO A VARIABLE
case class Student(name: String, grade: Int)
val goodStudent: Student => Boolean =
student => student.grade > 3
assert(goodStudent(Student("John", 4)) == true)
assert(goodStudent(Student("Adam", 3)) == false)
PASSING FUNCTION TO A HIGH-ORDER
FUNCTION
// List high-order function
def count(predicate: Student => Boolean): Int
val students = List(Student("John", 4), Student("Adam", 3))
val counter = students.count(goodStudent)
assert(counter == 1)
RETURNING FUNCTION FROM A HIGH-ORDER
FUNCTION
// high-order function
def gradeHigherThen(threshold: Int): Student => Boolean =
student => student.grade > threshold
val above3 = gradeHigherThen(3)
val above4 = gradeHigherThen(4)
val counter = students.count(above3)
PARTIAL FUNCTIONS
trait PartialFunction[-A, +B] extends (A => B) {
def isDefinedAt(x: A): Boolean
}
val improveGrade: PartialFunction[Student, Student] = {
case student if student.name == "John" =>
student.copy(grade = 5)
}
SCALA COLLECTIONS
Immutable/mutable
Operated by pure functions
LISTS
val numbers = List(2, 3)
val moreNumbers = 1 :: numbers // List(1, 2, 3)
moreNumbers.count(n => n > 2) // 1
val oddNumbers = moreNumbers.filter(n => n % 2 != 0) // List(1, 3)
val squares = moreNumbers.map(n => n * n) // List(1, 4, 9)
SETS
val letters = Set("a", "b", "a", "c") // Set(a, b, c)
val moreLetters = letters + "d" // Set(a, b, c, d)
val upperLetters = moreLetters.map(l => l.toUpperCase)
// Set(A, B, C, D)
MAPS
val students = Map("John" -> 4, "Adam" -> 3)
val moreStudents = students + ("Robert" -> 5)
moreStudents.map {
case (name, grade) => name -> (grade + 1)
}
AND THERE IS MORE
Futures
Implicits
Type Classes
Generic Classes
...
LEARN MORE
scala-lang.org
Programming in Scala, First Edition - artima.com/pins1ed
The Neophyte's Guide to Scala -
danielwestheide.com/scala/neophytes.html
Twitter's Scala School - twitter.github.io/scala_school
scala-exercises.org
COURSERA
Functional Programming Principles in Scala
Functional Program Design in Scala
THANK YOU
QUESTIONS ???

More Related Content

What's hot

javascript
javascript javascript
javascript
Kaya Ota
 

What's hot (15)

PHP PPT FILE
PHP PPT FILEPHP PPT FILE
PHP PPT FILE
 
DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail DBIx-DataModel v2.0 in detail
DBIx-DataModel v2.0 in detail
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
Basic Object Oriented Concepts
Basic Object Oriented ConceptsBasic Object Oriented Concepts
Basic Object Oriented Concepts
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
The underestimated power of KeyPaths
The underestimated power of KeyPathsThe underestimated power of KeyPaths
The underestimated power of KeyPaths
 
Js types
Js typesJs types
Js types
 
Web 6 | JavaScript DOM
Web 6 | JavaScript DOMWeb 6 | JavaScript DOM
Web 6 | JavaScript DOM
 
javascript
javascript javascript
javascript
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
Introduzione JQuery
Introduzione JQueryIntroduzione JQuery
Introduzione JQuery
 
Scala 101
Scala 101Scala 101
Scala 101
 
perl-pocket
perl-pocketperl-pocket
perl-pocket
 
PHP OOP
PHP OOPPHP OOP
PHP OOP
 
A quick python_tour
A quick python_tourA quick python_tour
A quick python_tour
 

Viewers also liked

9781119101987RetailNetworksForDummies_15954 (1)
9781119101987RetailNetworksForDummies_15954 (1)9781119101987RetailNetworksForDummies_15954 (1)
9781119101987RetailNetworksForDummies_15954 (1)
Alec Thorkelson
 
Del Tingo Al Tango_ From Here to There
Del Tingo Al Tango_ From Here to ThereDel Tingo Al Tango_ From Here to There
Del Tingo Al Tango_ From Here to There
Jasmine Nation
 

Viewers also liked (20)

Rekabentuk mesra OKU
Rekabentuk mesra OKURekabentuk mesra OKU
Rekabentuk mesra OKU
 
Brochure Acqua Group
Brochure Acqua GroupBrochure Acqua Group
Brochure Acqua Group
 
MAdissertation
MAdissertationMAdissertation
MAdissertation
 
Question 3
Question 3 Question 3
Question 3
 
Presentazione Club4business
Presentazione Club4businessPresentazione Club4business
Presentazione Club4business
 
9781119101987RetailNetworksForDummies_15954 (1)
9781119101987RetailNetworksForDummies_15954 (1)9781119101987RetailNetworksForDummies_15954 (1)
9781119101987RetailNetworksForDummies_15954 (1)
 
THYMIO-130513
THYMIO-130513THYMIO-130513
THYMIO-130513
 
mapas mentales
mapas mentalesmapas mentales
mapas mentales
 
silla de trabajo desplazable para un estudiante con movilidad reducida
silla de trabajo desplazable para un estudiante con movilidad reducidasilla de trabajo desplazable para un estudiante con movilidad reducida
silla de trabajo desplazable para un estudiante con movilidad reducida
 
MyCV
MyCVMyCV
MyCV
 
Momento inercia
Momento inerciaMomento inercia
Momento inercia
 
Design presentation #1
Design presentation #1Design presentation #1
Design presentation #1
 
CaseStudies
CaseStudiesCaseStudies
CaseStudies
 
International clearing union.pptx 2
International clearing union.pptx 2International clearing union.pptx 2
International clearing union.pptx 2
 
Del Tingo Al Tango_ From Here to There
Del Tingo Al Tango_ From Here to ThereDel Tingo Al Tango_ From Here to There
Del Tingo Al Tango_ From Here to There
 
Content marketing 101
Content marketing 101Content marketing 101
Content marketing 101
 
GMPacketFLAAB(20)
GMPacketFLAAB(20)GMPacketFLAAB(20)
GMPacketFLAAB(20)
 
Knowledge management
Knowledge managementKnowledge management
Knowledge management
 
BVServices
BVServicesBVServices
BVServices
 
Final SHOT plan
Final SHOT planFinal SHOT plan
Final SHOT plan
 

Similar to Scala Quick Introduction

pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
parag978978
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
Joe Zulli
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
John De Goes
 

Similar to Scala Quick Introduction (20)

Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Intro to scala
Intro to scalaIntro to scala
Intro to scala
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
The Death of Final Tagless
The Death of Final TaglessThe Death of Final Tagless
The Death of Final Tagless
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 

Recently uploaded

Recently uploaded (20)

OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 

Scala Quick Introduction

  • 2. AGENDA A little bit about Scala Basic syntax Object-oriented Scala Functional Scala Live code
  • 3. SCALA General purpose programming language Multiparadigm: object-oriented & functional Statically typed Runs on the JVM Created by Martin Odersky First release in 2004
  • 4. GET STARTED WITH SCALA Binaries scala-lang.org/download SBT scala-sbt.org/download IDE Scala IDE (Eclipse), IntelliJ, NetBeans
  • 5. SBT A build tool for Scala, Java and more scala-sbt.org
  • 6. FIRST APP object HelloWorld { def main(args: Array[String]): Unit = { println("Hello, World!") } }
  • 7. BASIC SYNTAX val name: String = "John" var age: Int = 30 i = 31 def add(x: Int, y: Int): Int = { x + y }
  • 8. STRING INTERPOLATION val name: String = "John" println(s"Hello $name")
  • 9. MULTILINE STRINGS val text: String = """ |This text spans |multiple lines. """.stripMargin
  • 10. STATICALLY TYPED LANGUAGE var name: String = "John" name = "Mark" name = 2 // compilation error !!! def add(x: Int, y: Int): Int = x + y add(1, "two") // compilation error !!!
  • 11. TYPE INFERENCE val name = "John" val age = 30 def add(x: Int, y: Int): Int = x + y val sum = add(1, 2)
  • 12. OBJECT-ORIENTED SCALA Everything is an object val x = 10 x.toString
  • 13. CLASSES abstract class Vehicle { def move(): Unit } class Car extends Vehicle { override def move(): Unit = { println("driving") } }
  • 14. TRAITS trait Diving { val deep = 100 def dive(): String = s"diving $deep meters" } class Car extends Vehicle with Diving { override val deep = 200 override def move(): Unit = { println(dive()) } }
  • 15. OBJECTS object SeeDiving { val MaxDepth = 500 def pressure(depth: Int): Double = depth / 10 * 0.99 } class Car extends Vehicle with Diving { override val deep: Int = SeeDiving.MaxDepth override def move(): Unit = { println(dive() + s" with ${SeeDiving.pressure(deep)} atm") } }
  • 16. CASE CLASSES // declare case class User(email: String, password: String) // create val admin = User("admin@company.com", "buddy") // access fields val adminEmail = admin.email // create copy val otherAdmin = admin.copy(email = "admin2@company.com") // compare assert(admin != otherAdmin)
  • 17. PATTERN MATCHING val result = something match { case "value" => "it's String equal to 'value'" case 10 => "it's Int equal to 10" case s: String => "it's String with value: " + s case _ => "it's something else" }
  • 18. PATTERN MATCHING AND CASE CLASSES val result = user match { case User("admin@company.com", "buddy") => "it's administrator" case User(email, password) => "it's " + email + ", his password is: " + password }
  • 21. FIRST-CLASS FUNCTIONS Function is a first-class citizen Can be assigned to a variable Can be passed as an argument of a function Can be returned from a function
  • 22. HIGH-ORDER FUNCTIONS Take other functions as an argument Return functions as a result
  • 23. SCALA FUNCTIONS // function type (Int, Int) => Int // anonymous function (x: Int, y: Int) => x + y
  • 24. ASSIGNING FUNCTION TO A VARIABLE case class Student(name: String, grade: Int) val goodStudent: Student => Boolean = student => student.grade > 3 assert(goodStudent(Student("John", 4)) == true) assert(goodStudent(Student("Adam", 3)) == false)
  • 25. PASSING FUNCTION TO A HIGH-ORDER FUNCTION // List high-order function def count(predicate: Student => Boolean): Int val students = List(Student("John", 4), Student("Adam", 3)) val counter = students.count(goodStudent) assert(counter == 1)
  • 26. RETURNING FUNCTION FROM A HIGH-ORDER FUNCTION // high-order function def gradeHigherThen(threshold: Int): Student => Boolean = student => student.grade > threshold val above3 = gradeHigherThen(3) val above4 = gradeHigherThen(4) val counter = students.count(above3)
  • 27. PARTIAL FUNCTIONS trait PartialFunction[-A, +B] extends (A => B) { def isDefinedAt(x: A): Boolean } val improveGrade: PartialFunction[Student, Student] = { case student if student.name == "John" => student.copy(grade = 5) }
  • 29. LISTS val numbers = List(2, 3) val moreNumbers = 1 :: numbers // List(1, 2, 3) moreNumbers.count(n => n > 2) // 1 val oddNumbers = moreNumbers.filter(n => n % 2 != 0) // List(1, 3) val squares = moreNumbers.map(n => n * n) // List(1, 4, 9)
  • 30. SETS val letters = Set("a", "b", "a", "c") // Set(a, b, c) val moreLetters = letters + "d" // Set(a, b, c, d) val upperLetters = moreLetters.map(l => l.toUpperCase) // Set(A, B, C, D)
  • 31. MAPS val students = Map("John" -> 4, "Adam" -> 3) val moreStudents = students + ("Robert" -> 5) moreStudents.map { case (name, grade) => name -> (grade + 1) }
  • 32. AND THERE IS MORE Futures Implicits Type Classes Generic Classes ...
  • 33. LEARN MORE scala-lang.org Programming in Scala, First Edition - artima.com/pins1ed The Neophyte's Guide to Scala - danielwestheide.com/scala/neophytes.html Twitter's Scala School - twitter.github.io/scala_school scala-exercises.org
  • 34. COURSERA Functional Programming Principles in Scala Functional Program Design in Scala
  • 35.
  • 36.