Scala in Action

Scala in Action

Nilanjan Raychaudhuri

Language: English

Pages: 530

ISBN: 1935182757

Format: PDF / Kindle (mobi) / ePub

Summary

Scala in Action is a comprehensive tutorial that introduces Scala through clear explanations and numerous hands-on examples. Because Scala is a rich and deep language, it can be daunting to absorb all the new concepts at once. This book takes a "how-to" approach, explaining language concepts as you explore familiar programming challenges that you face in your day-to-day work.

About the Technology

Scala runs on the JVM and combines object-orientation with functional programming. It's designed to produce succinct, type-safe code, which is crucial for enterprise applications. Scala implements Actor-based concurrency through the amazing Akka framework, so you can avoid Java's messy threading while interacting seamlessly with Java.

About this Book

Scala in Action is a comprehensive tutorial that introduces the language through clear explanations and numerous hands-on examples. It takes a "how to" approach, explaining language concepts as you explore familiar programming tasks. You'll tackle concurrent programming in Akka, learn to work with Scala and Spring, and learn how to build DSLs and other productivity tools. You'll learn both the language and how to use it.

Experience with Java is helpful but not required. Ruby and Python programmers will also find this book accessible.

What's Inside
• A Scala tutorial
• How to use Java and Scala open source libraries
• How to use SBT
• Test-driven development
• Debugging
• Updated for Scala 2.10

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Author

Nilanjan Raychaudhuri is a skilled developer, speaker, and an avid polyglot programmer who works with Scala on production systems.

This chapter introduces what and why functional programming is important to learn. Even if you don’t use Scala in your projects, some of the concepts introduced here can be used in any programming language. Part 2: Working with Scala Chapter 6 takes the first stab at building a large web application using Scala. This chapter will show you how to build and organize a Scala project and it introduces the popular Simple Build Tool (SBT). Chapter 7, a continuation of the previous chapter,

implicit conversion. We can combine the RangeMaker and conversion methods by making the class implicit: implicit class RangeMaker(left: Int) { def -->(right: Int): Range = left to right } Behind the scenes, the compiler will “desugar” the implicit class into a simple class and an implicit conversion method, as we did earlier. Note that implicit classes must have a primary constructor with one argument. Looking up an appropriate implicit conversion takes time, but it’s not much of an issue

collection in a scala.collection can be both mutable and immutable. You read about the difference between mutable and immutable collection classes in the previous section. Here you’ll focus on both mutable and immutable collections. But before I start looking into specific collection classes, let’s peek at the Iterable trait. This trait comes after Traversable. It provides the implementation of foreach that you learned in the last section and it exposes a new abstract method called iterator. It

for(Artist(name, genre) true; case _ => false } foreach { case Artist(name, genre) => println(name + "," + genre)} When you have multiple generators in the for-comprehension, things become a little more involved and interesting. Let’s say that along with the artists you also like to store albums produced by those artists, and you’re only interested in rock albums. Create another case class to store the

abstract type members and self type before you start building your component, because they’re important building blocks. 8.1.1. Abstract type members Scala takes the idea of abstract beyond methods and fields. You can also declare abstract type members inside a class or trait. Abstract types are those whose identity is unknown at the time of declaration. Unlike concrete types, the type of an abstract type member is specified during the concrete implementation of the enclosing class. The