Professional Scala (1119267250) cover image

Professional Scala

Janek Bogucki, Alessandro Lacava, Aliaksandr Bedrytski, Matthew de Detrich, Benjamin Neil
ISBN: 978-1-119-26725-6
E-book
215 pages
June 2016
Other Available Formats: Paperback
Electronic Version: US $40.99 Purchase This E-book

About This Title  |  Errata
Table of Contents
INTRODUCTION xv

CHAPTER 1: LANGUAGE FEATURES 1

Static Types and Type Inference 2

Implicit Parameters, Conversions, and Their Resolution 3

Case Class, Tuples, and Case Object 5

Abstract Class, Traits, and Sealed 6

Pattern Matching 8

Statements Are Expressions 9

String Interpolation 9

Scala Collections, immutable and mutable 10

For Comprehension 12

Packages, Companion Objects, Package Objects, and Scoping 13

AnyVal, AnyRef, Any, and the Type Hierarchy 16

Summary 17

CHAPTER 2: FUNCTIONAL PROGRAMMING 19

Immutability 20

Pure Functions 22

Recursion 23

Higher-Order Functions 26

Core Collection Methods 27

Methods Returning a Collection 29

Methods Returning a Value 31

Currying and Partially Applied Functions 32

Null Handling (Option) 34

Strict versus Non-Strict Initialization 35

Summary 36

CHAPTER 3: JAVA COMPATIBILITY 37

Scala and Java Collections 37

Interfaces and Traits 40

Scala/Java Enumerations 42

Summary 43

CHAPTER 4: SIMPLE BUILD TOOL 45

Basic Usage 46

Project Structure 47

Single Project 47

Scopes 49

Custom Tasks 50

Dependencies 50

Resolvers 51

Advanced Usage 52

Advanced Dependencies 53

Testing in the Console 55

Release Management 56

Deploying to Sonatype 56

Packaging with SBT-Native-Packager 58

Creating a Docker Image 59

Common SBT Commands 60

Useful Plugins 61

Summary 62

CHAPTER 5: MAVEN 63

Getting Started with Maven and Scala 64

Introducing scala-maven-plugin 67

Adding Library Dependencies 70

Using the REPL 71

Getting Help 72

Running Tests 72

Joint Compilation with Java 74

Accelerating Compilation with Zinc 76

Summary 77

CHAPTER 6: SCALA STYLE/LINT 79

Scala with Style 79

Scaliform 81

Scapegoat 82

WartRemover 82

Scoverage 84

Summary 84

CHAPTER 7: TESTING 85

ScalaTest 86

Unit Tests 87

Integration Testing 87

Data-Driven Tests 88

Performance Testing 89

Acceptance Testing 90

Mocks 92

Load Testing 93

Summary 94

CHAPTER 8: DOCUMENTING YOUR CODE WITH SCALADOC 95

Why Document Your Code? 96

Revealing the Benefi ts 96

Bookending the Continuum 96

Choosing What to Document 96

Scaladoc Structure 97

Overall Layout 97

Index Pane 98

Content Pane 100

Invoking the Scaladoc Tool 106

Wiki Syntax 108

Formatting with Inline Wiki Syntax 108

Structuring with Block Elements 110

Linking 113

Locating Scaladoc 117

Tagging 117

Everyday Tagging 117

Tagging for Groups 123

Advanced Tagging 125

Invoking scaladoc: Additional Options 132

Integrating Scaladoc Creation with Your Project 133

Configuring Maven 133

Configuring SBT 134

Publishing Scaladoc 134

Tables and CSS 136

Summary 138

CHAPTER 9: TYPE SYSTEM 139

What Is a Type System? 140

Static versus Dynamic Typing 140

What Static Type Systems Are Good For 141

What Dynamic Type Systems Are Good For 141

Scala’s Unified Type System 141

Value Classes 143

Polymorphism 145

Subtype Polymorphism 145

Parametric Polymorphism 146

Ad Hoc Polymorphism 146

Bounds 149

Context Bounds 149

Upper and Lower Bounds 150

Variance 151

Other Niceties 155

Self-Type Annotations 155

Self-Recursive Types 158

Abstract Type Members 159

Dynamic Programming 161

Structural Types 161

Dynamic Trait 162

Summary 164

CHAPTER 10: ADVANCED FUNCTIONAL PROGRAMMING 165

Higher-Kinded Types 165

Functional Design Patterns 167

Functor 167

Applicative Functor 170

Monad 172

Semigroup 173

Monoid 174

Summary 176

CHAPTER 11: CONCURRENCY 179

Synchronize/Atomic Variables 181

Future Composition 184

Parallel Collections 187

Reactive Streams 192

STM 195

Actors (Akka) 198

Spark 200

Summary 202

CHAPTER 12: SCALA.JS 205

Scala.js and Its Design 205

Getting Started: Scala.js with SBT 206

Scala.js Peculiarities 210

Webjars and Dealing with the Frontend Ecosytem 211

Summary 213

INDEX 215