Beyond Java to Scala

This part of the book is all about the differences between Scala and Java. There are plenty of language features in Scala that don’t have an obvious analog in Java. In this part, we’ll take a closer look at some of those and explore what Scala can give us over Java.

Specifically, we’ll explore a number of the language features that make writing Scala more expressive and we’ll look at some of the more functional programming idioms that Scala is so well know for.

Expressive Scala

Scala offers several features that make writing code more concise. As well as some we’ve already seen, it provides mechanisms to:

  • Make methods look like functions using the special case apply method.

  • Provide default behavior for the assignment operator using a special case update method.

  • Make regular method calls look like language structures, which in effect means you can define your own control structures.

Scala also offers pattern matching; we’ll look at the unapply method and its role in pattern matching.

Functional Programming Idioms

We’ll also look at some of functional programming aspects of Scala .

  • Built-in methods for mapping values (map, flatMap).

  • What monads are and why you should care.

  • The Option class as a way of avoiding null checks.

  • Chaining monad calls.

  • For comprehensions and how they work under the hood.

This only scratches the surface of functional programming but I hope that this part of the book will give you a useful head start when it comes to Scala and functional programming.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.195.111