Chapter 2. Getting started

 

This chapter covers

  • Working with the Scala REPL
  • Scala basics
  • For-comprehensions and pattern matching
  • Building a complete REST client in Scala

In chapter 1 you learned what Scala is and how it compares to other programming languages. I described the concepts at a high level, and in the next few chapters you’re going to revisit those concepts and explore them in detail using examples. In this chapter you learn about the basic Scala types, functions, for-comprehensions, pattern matching, and the other usual suspects.

Some of the concepts in this chapter, like pattern matching and for-comprehensions, are functional programming concepts. But because Scala is a multi-paradigm language, I cover them with the rest of the nonfunctional programming concepts. The objective of this chapter is for you to become comfortable with the basics of the Scala language and its environment so you can start writing Scala programs. Early on, I focus on only the Scala interpreter and its REPL environment (you’ll see it in the next section) to keep things simple.

Before going any farther, make sure your Scala installation is working. Throughout the chapter you’re going to work with various Scala examples, and it would be better if you tried them in the Scala interpreter at the same time. Now let’s have some fun with the Scala interpreter.

2.1. REPL with Scala interpreter

2.2. Scala basics

2.3. Working with Array and List

2.4. Controlling flow with loops and ifs

2.5. For-comprehensions

2.6. Pattern matching

2.7. Exception handling

2.8. Command-line REST client: building a working example

2.9. Summary