Scala is a multi-style programming language for the JVM that supports both object-oriented and functional programming. Master Scala, and you'll be well-equipped to match your programming approach to the type of problem you're dealing with. Packed with examples and exercises, Get Programming with Scala is perfect starting point for developers with some OO knowledge who want to learn Scala and pick up a few FP skills along the way.
Explains the basics of the language in a very simple and captivating way.
Unit 0: Hello Scala!
Lesson 1: Why Scala?
1.1 Scala and the JVM
1.2 Scala’s key features
1.3 Advantages of adopting Scala
Lesson 2: Scala — The REPL
2.1 The REPL Commands
2.2 The REPL Code Evaluation
Lesson 3: SBT — Scala Build Tool
3.1 SBT Commands
3.2 Your first SBT Project
3.3 SBT Project Structure
Unit 1: Statements, Expressions, and Values
Lesson 4: Values and Variables
4.3 Lazy Values
4.5 Answers to quick checks
Lesson 5: Conditional Statements
5.1 If…else statement
5.2 Pattern matching
5.4 Answers to quick checks
Lesson 6: Import and Packages
6.1 Import an existing Package
6.2 Create a Package
6.3 Create a Package Object
6.5 Answers to Quick Checks
Lesson 7: Access Modifiers
7.1 Default Access Modifier
7.4 Package private
7.5 Which Access Modifier to use?
7.7 Answers to Quick Checks
Lesson 8: Let’s build a vending machine!
8.1 The Vending Machine: customer flow
8.1.1 The VendingMachine class and its APIs
8.1.2 The Vending Machine and its operations
8.2 The Vending Machine: operator flow
8.2.1 The Operator class and its APIs
8.2.2 The Operator: collecting Money and adding products
8.2.3 Let’s try it out
8.3 The ugly bits of our solution
Unit 2: Structure your Code
Lesson 9: Classes and Subclasses to represent the world
9.3 Abstract class
9.4 Anonymous Class
9.6 Answers to Quick Checks
Lesson 10: Objects are important too!
10.1.1 Object as executable program
10.2 Companion Object
10.2.1 The Apply Method
10.4 Answers to Quick Checks
Lesson 11: Traits as composable blocks of code
11.1 Fragments of code on steroids
11.2 Trait versus Abstract Class
11.3 Seal traits
11.5 Answers to Quick Checks
Lesson 12: Case Classes to structure your data
12.1 Case class
12.2 Case object
12.5 Answers to Quick Checks
Lesson 13: Rock, Paper, Scissors, Lizard, Spock!
13.1 Implementing Rock, Paper, Scissor, Lizard, Spock!
13.1.1 What’s a symbol?
13.1.2 Defining each symbol
13.1.3 The Game representation
13.1.4 Let’s give it a try
Unit 3: Functions
Lesson 14: Function as the most fundamental block of code
Lesson 15: Pure and Impure Functions
Lesson 16: Anonymous Functions
Lesson 17: High Order Functions
Lesson 18: Capstone 3: Travelling across Europe
Unit 4: Collections
Lesson 19: Immutable and Mutable collections
Lesson 20: Working with List
Lesson 21: Working with Map
Lesson 22: Common operations on collections
Lesson 23: Capstone 4: Hotel Management Service
Unit 5: Common types
Lesson 24: Option a way to represent nullable data
Lesson 25: Either one or the other
Lesson 26: Try an operation that can fail
Lesson 27: Future an operation that takes time
Lesson 28: Capstone 5
Unit 6: Even more functions
Lesson 29: Recursive Functions
Lesson 30: Partial Functions
Lesson 31: Curry and Closures
Lesson 32: Function composition
Lesson 33: Capstone 6
Unit 7: Abstractions never repeat yourself
Lesson 34: Generics hide details that do not matter
Lesson 35: Bound your types
Lesson 36: Type aliases
Lesson 37: Higher Kinded Types
Lesson 38: Capstone 7
Unit 8: Make your code maintainable
Lesson 39: Testing
Lesson 40: Property-base testing
Lesson 41: Write code that looks nice
Lesson 42: Do only one things, do it right
Lesson 43: Capstone 8
Unit 9: Scala tricks that make your life easier
Lesson 44: Data validation
Lesson 45: More on For-comprehensions
Lesson 46: Pimp your library
Lesson 47: Type Classes
Lesson 48: Capstone 10
About the TechnologyAlthough it's a relative newcomer, Scala turned out to be the right language at the right time, opening up the world of functional programming to the JVM. Scala looks a lot like Java, and it interacts seamlessly with familiar Java libraries and tools. Since it fully supports functional programming, Scala gives you the freedom to choose the right programming style exactly when it benefits you. Scala can be daunting at first, especially if you're seeing FP ideas for the first time. Fortunately, with the examples and exercises in this book, you'll get over the initial learning hump quickly and start doing interesting projects before you know it!
About the bookGet Programming with Scala teaches you the core skills you'll need to code with Scala. This book lives up to its name! You'll learn the ins and outs of Scala by actually programming with it, thanks to the practical examples, exercises, and easy-to-follow lessons. You'll start by reviewing OOP concepts in the Scala language. Then, example-by-example, you'll gradually open up the world of functional programming. You'll explore functions and types and learn how to combine them to create powerful, flexible abstractions. Along the way, you'll learn some Scala testing and get an intuition for sniffing out and fixing code that doesn't smell quite right.
- Learn to express OO principles in Scala
- Express your program designs in functions
- Make use of types to enforce program requirements
- Use abstractions to avoid code duplication
- Write meaningful tests and recognize code smells
About the readerWritten for developers with some prior experience in an OOP language like Java or C#. No experience with Scala or functional programming is needed.
About the authorDaniela Sfregola started working with Scala in 2013. Since then she has been an active contributor to the Scala Community. Daniela currently maintains several open source projects in the community and regularly speaks at Scala conferences. She blogs about Scala regularly at https://danielasfregola.com/.
Lots of code snippets and examples make it easy to learn a language that has a reputation of being difficult.
If you know nothing about Scala and you want to learn it, this is your book.