Scala is a type-safe JVM language that incorporates both object-oriented and
functional programming into an extremely concise, logical, and extraordinarily
powerful language. Some may be surprised to know that Scala is not quite as new
as they may have thought, having first been introduced in 2003. However, it is in the
past few years in particular that Scala has begun to develop a significant following.
This book enables you to build and contribute to Scala programs, recognizing
common patterns and techniques used with the language.
This is a practical book which provides you with a lot of hands-on experience
with Scala.
This book is for developers who are interested in learning about the advanced
features of the Scala language. Basic knowledge of the Scala programming language
is required to follow the instructions in this book
Author(s): Mads Hartmann, Ruslan Shevchenko
Publisher: Packt
Year: 2018
Language: English
Commentary: True PDF
Pages: 186
Table of Contents......Page 7
Preface......Page 15
Setting up the Development Environment......Page 21
Object Definition......Page 23
Inside main......Page 24
Structure of a Scala Project......Page 26
Basic sbt Commands......Page 28
IDE......Page 29
REPL......Page 30
Obtaining the Time Request from Our Chatbot Program......Page 31
Base Syntax......Page 32
Base Syntax for Definitions......Page 33
Base Syntax for Expressions......Page 34
Adding a Test to Our Project......Page 36
Inside Tests......Page 38
Running Tests for Chatbot......Page 39
Summary......Page 43
Basic Language Features......Page 45
Object......Page 46
Classes......Page 47
Equality and Case Classes......Page 49
Pattern Matching......Page 51
Traits......Page 52
Self-Types......Page 55
Decoupling Logic and Environment......Page 58
Sealed Traits and Algebraic Datatypes......Page 60
Default Parameters......Page 65
Parameter-Passing Mode......Page 67
By Name......Page 68
Creating a Runnable Construction......Page 69
Printing the log Argument to the Console
and File......Page 70
Summary......Page 71
Functions......Page 73
Function Values......Page 74
Function from an OO Point of View......Page 75
Conversions......Page 76
Defining and Measuring the Time of a Unit Function......Page 77
Partial Functions......Page 78
Exploring Pattern Matching......Page 80
Binding a Sequence of Variables in the Pattern Matcher......Page 82
Representing ChatbotMode as a Partial Function......Page 84
Implementing RemindStore as a Set of Partial Functions......Page 86
Using Lifting for Conversations between Total and Partial Functions......Page 87
Summary......Page 90
Scala Collections......Page 91
Constructing Lists......Page 92
Pattern Matching on Lists......Page 93
Appending and Concatenation......Page 94
Element Selection......Page 95
Display......Page 96
Abstracting on Sequences......Page 97
The Traversable Trait......Page 98
Iterators......Page 99
Activity: Implementing Fibonacci Series Using Streams and Iterators......Page 100
Tuples......Page 101
Mutable and Immutable Collections......Page 102
Activity: Implementing the Tower of Hanoi Problem......Page 104
Summary......Page 105
Scala Type System......Page 107
Parametric Polymorphism......Page 108
Type Inference......Page 109
Existential Types......Page 110
Activity: Generalizing the Implementation of the Binary Tree......Page 112
Variance......Page 113
Covariance......Page 114
Invariance......Page 115
Abstract Type Members......Page 117
Structural Types......Page 118
Option......Page 119
Type Erasure......Page 120
Summary......Page 121
Implicits......Page 123
Implicit Parameters......Page 124
Implicit Conversions......Page 125
Implicit Resolution......Page 126
Activity: Creation of Extension Methods......Page 127
Type Classes......Page 128
Context Bounds and Implicitly......Page 129
Type Classes in the Standard Library......Page 130
Summary......Page 131
Functional Idioms......Page 133
Pure Functions......Page 134
Immutability......Page 136
Higher-Order Functions......Page 137
Functional Design Patterns......Page 139
Monoids......Page 140
Functor......Page 142
Monads......Page 144
Prerequisites for Using Cats......Page 146
Validating Data......Page 147
Validating Using Validated......Page 148
Prerequisites for Doobie......Page 150
Transactor......Page 151
Selecting Rows......Page 152
Querying Using Parameters......Page 153
Deleting, Inserting, and Updating Rows......Page 154
A Complete Example......Page 155
Summary......Page 156
Domain Specific Languages......Page 157
External DSLs......Page 158
ScalaTest – A Popular DSL......Page 159
Adding ScalaTest to Your Project......Page 160
Overview of ScalaTest Styles......Page 161
Language Features for Writing DSLs......Page 165
By-Name Parameters......Page 166
Writing a Small DSL......Page 167
Modeling Test Cases......Page 168
DSL for TestCase......Page 169
Activity: Creating a DSL to Specify Assertions......Page 171
Akka......Page 172
Shapeless......Page 173
Macros......Page 174
Implicit Macros......Page 175
Reflection......Page 176
Scala Improvement Process......Page 177
Summary......Page 178
Index......Page 179