Contents

About the Authors

About the Technical Reviewer

Introduction

image Chapter 1: Getting Started with Scala

Why Scala?

A Concise Language

Lightweight Syntax

Multiparadigm Language

Interoperability and Seamless Integration with Java

Language for the Java Virtual Machine

Installing Scala

Scala at the Command Line and Scala Scripts

Interactive Scala

Scala Scripts

Compiling Scala Programs

Your First Scala Programs

Hello World

Printing Some Numbers

Summary

image Chapter 2: Basics of Scala

Variables

Scala Type Hierarchy

Any, AnyVal and AnyRef Types

Numeric Types

Boolean Type

Char Type

Unit type

Nothing and Null Types

Strings

String Interpolation

Functions

Function without Parameter

Function with Parameters

Arrays, Lists, Ranges, and Tuples

Arrays

Lists

Ranges

Tuples

Built-in Control Structures

If Expressions

While Loops

For Comprehension

try expressions

Match Expressions

Comments

Summary

image Chapter 3: Object Orientation in Scala

Classes and Objects

Constructors

Method Declaration

Code Blocks

Call-by-Name

Method Invocation

Objects

Packaging and Imports

Inheritance

Extending Class

Traits

Case Classes

Value Classes

Scala versus Java versus Ruby

Classes and Instances

Traits, Interfaces, and Mixins

Object, Static, and Singletons

Functions, Anonymous Inner Classes, and Lambdas/Procs

Summary

image Chapter 4: Functional Programming in Scala

Expression-Oriented Programming

A Pure Function

Referential Transparency

Function Literal/Anonymous Function

First Class Function and Higher Order Function

Function as Variable

Function as Parameter

Returning a Function

Closure

Partially Applied Function

Curried Function

Function Composition

Tail Calls and Tail Call Optimization

Call-by-Name, Call-by-Value, and General Laziness

Summary

image Chapter 5: Pattern Matching

Basic Pattern Matching

Matching Any Type

Pattern Matching in Lists

Pattern Matching and Lists

Pattern Matching and Case Classes

Nested Pattern Matching in Case Classes

Pattern Matching As Functions

Object-Oriented and Functional Tensions

Shape Abstractions

Summary

image Chapter 6: Scala Collections

Scala Collection Hierarchy

package scala.collection

package scala.collection.immutable

package scala.collection.mutable

Using Immutable Collection Classes

Vector

List[T]

Range

Stream

Tuples

Map[K, V]

Mutable Collections

Summary

image Chapter 7: Traits

Using Traits as Mixins

Traits and Class Hierarchies

Summary

image Chapter 8: Scala Type System

Unified Type System

Type Parameterization

Variance

Rules of Variance

Type Bounds

Upper Type Bounds

Lower Type Bounds

Implicit Class

Abstract Types

Higher-Kinded Types

Summary

image Chapter 9: Scala and Java Interoperability

Translating Java Classes to Scala Classes

JavaBeans Specification Compliant Scala Classes

Java Interfaces and Scala Traits

Java Static Members and Scala Objects

Handling Exceptions

Summary

image Chapter 10: DSL and Parser Combinator

Domain Specific Language (DSL)

Internal DSLs

External DSLs

Parser Combinator

Higher-Order Functions and Combinators

Combinators

The Calculator Parser

Summary

image Chapter 11: Simple Build Tool - SBT

Getting Started with SBT

Installing SBT

Creating Hello World Project

Build Definition

LibraryDependencies and Resolvers

Plugins

Summary

image Chapter 12: Scala for Web Application

Scala Web Frameworks

Lift

Play 2

Getting Started with the Standalone Distribution

Anatomy of Play Application

MVC in Play 2

HelloWorld Java Application with Play

Getting Started with the Activator Distribution

Actions, Controllers, and Results

Summary

image Chapter 13: Scala Best Practices

Recognizing the Functional Style

Writing Pure Functions

Leverage Type Inferencing

Think Expressions

Focus on Immutability

Keep Methods Short

Use Options Instead of Null Testing

Refactor Mercilessly

Compose Functions and Compose Classes

Scala Design Patterns

Singleton

Factory Method

Strategy

Template Method

Adapter

Summary

Index

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

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