Beginning Scala, Second Edition

Book description

Beginning Scala, Second Edition takes a down-to-earth approach to teaching Scala that leads you through simple examples that can be combined to build complex, scalable systems and applications.

This book introduces you to the Scala programming language, its object-oriented and functional programming characteristics, and then guides you through Scala constructs and libraries that allow you to assemble small components into high-performance, scalable systems. You will learn why Scala is judiciously used for critical business applications by leading companies such as Twitter, LinkedIn, Foursquare, the Guardian, Morgan Stanley, Credit Suisse, UBS, and HSBC.

Scala is a multi-paradigm programming language that combines both functional and object-oriented features. Moreover, this highly scalable language lends itself well to building cloud-based/deliverable Software as a Service (SaaS) online applications.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Contents at a Glance
  5. Contents
  6. About the Authors
  7. About the Technical Reviewer
  8. Introduction
  9. Chapter 1: Getting Started with Scala
    1. Why Scala?
      1. A Concise Language
      2. Lightweight Syntax
      3. Multiparadigm Language
      4. Interoperability and Seamless Integration with Java
      5. Language for the Java Virtual Machine
    2. Installing Scala
    3. Scala at the Command Line and Scala Scripts
      1. Interactive Scala
      2. Scala Scripts
      3. Compiling Scala Programs
    4. Your First Scala Programs
      1. Hello World
      2. Printing Some Numbers
    5. Summary
  10. Chapter 2: Basics of Scala
    1. Variables
    2. Scala Type Hierarchy
      1. Any, AnyVal and AnyRef Types
      2. Numeric Types
      3. Boolean Type
      4. Char Type
      5. Unit type
      6. Nothing and Null Types
    3. Strings
      1. String Interpolation
    4. Functions
      1. Function without Parameter
      2. Function with Parameters
    5. Arrays, Lists, Ranges, and Tuples
      1. Arrays
      2. Lists
      3. Ranges
      4. Tuples
    6. Built-in Control Structures
      1. If Expressions
      2. While Loops
      3. For Comprehension
      4. try expressions
      5. Match Expressions
    7. Comments
    8. Summary
  11. Chapter 3: Object Orientation in Scala
    1. Classes and Objects
      1. Constructors
      2. Method Declaration
      3. Code Blocks
      4. Call-by-Name
      5. Method Invocation
      6. Objects
    2. Packaging and Imports
    3. Inheritance
      1. Extending Class
    4. Traits
    5. Case Classes
    6. Value Classes
    7. Scala versus Java versus Ruby
      1. Classes and Instances
      2. Traits, Interfaces, and Mixins
      3. Object, Static, and Singletons
      4. Functions, Anonymous Inner Classes, and Lambdas/Procs
    8. Summary
  12. Chapter 4: Functional Programming in Scala
    1. Expression-Oriented Programming
    2. A Pure Function
      1. Referential Transparency
    3. Function Literal/Anonymous Function
    4. First Class Function and Higher Order Function
      1. Function as Variable
      2. Function as Parameter
      3. Returning a Function
    5. Closure
    6. Partially Applied Function
    7. Curried Function
    8. Function Composition
    9. Tail Calls and Tail Call Optimization
    10. Call-by-Name, Call-by-Value, and General Laziness
    11. Summary
  13. Chapter 5: Pattern Matching
    1. Basic Pattern Matching
      1. Matching Any Type
      2. Pattern Matching in Lists
      3. Pattern Matching and Lists
    2. Pattern Matching and Case Classes
      1. Nested Pattern Matching in Case Classes
    3. Pattern Matching As Functions
    4. Object-Oriented and Functional Tensions
      1. Shape Abstractions
    5. Summary
  14. Chapter 6: Scala Collections
    1. Scala Collection Hierarchy
      1. package scala.collection
      2. package scala.collection.immutable
      3. package scala.collection.mutable
    2. Using Immutable Collection Classes
      1. Vector
      2. List[T]
      3. Range
      4. Stream
      5. Tuples
      6. Map[K, V]
    3. Mutable Collections
    4. Summary
  15. Chapter 7: Traits
    1. Using Traits as Mixins
    2. Traits and Class Hierarchies
    3. Summary
  16. Chapter 8: Scala Type System
    1. Unified Type System
    2. Type Parameterization
      1. Variance
      2. Rules of Variance
    3. Type Bounds
      1. Upper Type Bounds
      2. Lower Type Bounds
    4. Implicit Class
    5. Abstract Types
      1. Higher-Kinded Types
    6. Summary
  17. Chapter 9: Scala and Java Interoperability
    1. Translating Java Classes to Scala Classes
    2. JavaBeans Specification Compliant Scala Classes
    3. Java Interfaces and Scala Traits
    4. Java Static Members and Scala Objects
    5. Handling Exceptions
    6. Summary
  18. Chapter 10: DSL and Parser Combinator
    1. Domain Specific Language (DSL)
      1. Internal DSLs
      2. External DSLs
    2. Parser Combinator
      1. Higher-Order Functions and Combinators
      2. Combinators
      3. The Calculator Parser
    3. Summary
  19. Chapter 11: Simple Build Tool - SBT
    1. Getting Started with SBT
      1. Installing SBT
      2. Creating Hello World Project
    2. Build Definition
    3. LibraryDependencies and Resolvers
    4. Plugins
    5. Summary
  20. Chapter 12: Scala for Web Application
    1. Scala Web Frameworks
      1. Lift
      2. Play 2
    2. Getting Started with the Standalone Distribution
      1. Anatomy of Play Application
      2. MVC in Play 2
      3. HelloWorld Java Application with Play
    3. Getting Started with the Activator Distribution
    4. Actions, Controllers, and Results
    5. Summary
  21. Chapter 13: Scala Best Practices
    1. Recognizing the Functional Style
    2. Writing Pure Functions
    3. Leverage Type Inferencing
    4. Think Expressions
    5. Focus on Immutability
    6. Keep Methods Short
    7. Use Options Instead of Null Testing
    8. Refactor Mercilessly
    9. Compose Functions and Compose Classes
    10. Scala Design Patterns
      1. Singleton
      2. Factory Method
      3. Strategy
      4. Template Method
      5. Adapter
    11. Summary
  22. Index

Product information

  • Title: Beginning Scala, Second Edition
  • Author(s): Vishal Layka, David Pollak
  • Release date: February 2015
  • Publisher(s): Apress
  • ISBN: 9781484202326