The second version of Scala has undergone multiple changes to support features and library implementations. Scala 2.13, with its main focus on modularizing the standard library and simplifying collections, brings with it a host of updates.
Learn Scala Programming addresses both technical and architectural changes to the redesigned standard library and collections, along with covering in-depth type systems and first-level support for functions. You will discover how to leverage implicits as a primary mechanism for building type classes and look at different ways to test Scala code. You will also learn about abstract building blocks used in functional programming, giving you sufficient understanding to pick and use any existing functional programming library out there. In the concluding chapters, you will explore reactive programming by covering the Akka framework and reactive streams.
By the end of this book, you will have built microservices and learned to implement them with the Scala and Lagom framework.
Author(s): Slava Schmidt
Publisher: Packt Publishing
Year: 2018
Language: English
Pages: 498
Cover......Page 1
Title Page......Page 2
Copyright and Credits......Page 3
Dedication......Page 4
Packt Upsell......Page 5
Contributors......Page 6
Table of Contents......Page 8
Preface......Page 16
Introduction to Scala 2.13......Page 23
Optional parsing for string literals......Page 24
Products can report the names of their element......Page 25
Added methods for chaining operations......Page 26
Automatic Resource Management......Page 28
The Scala 2.13 Collection Library......Page 29
IterableOnceOps......Page 31
IterableOps......Page 32
WithFilter......Page 33
View......Page 34
Set......Page 36
Map......Page 38
HashMap......Page 39
Seq......Page 40
IndexedSeq......Page 42
LinearSeq......Page 43
Buffers......Page 44
Scala Collection Contrib library......Page 45
Summary......Page 46
Further reading......Page 47
Technical requirements......Page 48
Ways to create a type......Page 49
Literal types......Page 50
Compound (intersection) types......Page 53
Type constraints......Page 54
Scala's types hierarchy and special types......Page 55
Type inference......Page 57
Path-dependent types......Page 58
Type parameters......Page 60
Type members......Page 61
Infix types......Page 64
Variance......Page 65
Existential types......Page 68
Higher kinded types......Page 69
Type lambdas......Page 70
Phantom types......Page 71
Self-recursive types......Page 74
Questions......Page 76
Further reading......Page 77
Technical requirements......Page 78
Function as a method......Page 79
Local functions......Page 81
Closures......Page 82
Partial application and functions......Page 83
Function literals ......Page 85
Polymorphism and higher order functions......Page 87
Polymorphic functions......Page 88
Higher-order functions......Page 89
Recursion and trampolining......Page 90
Recursion......Page 91
Tail recursion......Page 92
Trampolining......Page 94
Object-oriented aspects of functions......Page 95
Functions are traits......Page 96
Partial functions......Page 97
Function object......Page 98
Extending functions......Page 99
Questions......Page 100
Further reading......Page 101
Technical requirements......Page 102
Implicit conversions......Page 103
Implicit parameters......Page 106
Implicit classes......Page 109
View bounds......Page 110
Context bounds......Page 111
Type classes......Page 112
Type classes......Page 113
Type class recursive resolution......Page 115
Type class variance......Page 118
Implicit scope resolution......Page 120
Lexical scope......Page 121
Implicit scope......Page 122
Static overloading rules......Page 123
Summary......Page 124
Further reading......Page 125
Technical requirements......Page 126
From unit tests to properties......Page 127
ScalaCheck......Page 128
Commutativity......Page 129
Associativity......Page 130
Invariants......Page 131
Induction ......Page 132
Test Oracle......Page 133
Checking property......Page 134
Combining properties......Page 135
Generators......Page 136
Existing generators......Page 137
Combining generators......Page 138
Shrinkers......Page 141
Summary......Page 143
Questions......Page 144
Technical requirements......Page 145
Introduction to effects......Page 146
Creating an Option......Page 148
Reading from an Option......Page 149
Option as an effect......Page 151
Either......Page 154
Creating Either......Page 155
Reading values from Either......Page 156
Either as an Effect......Page 157
Try......Page 159
Creating a Try......Page 160
Reading values from Try......Page 161
Try as an effect......Page 162
Future......Page 164
Creating a Future......Page 165
Future as an effect......Page 166
Summary......Page 168
Questions......Page 169
Technical requirements......Page 170
Semigroup......Page 171
Monoid......Page 179
Foldable......Page 185
Group......Page 190
Summary......Page 192
Further reading......Page 193
Technical requirements......Page 194
Functor......Page 195
Applicative......Page 200
Traversable......Page 212
Summary......Page 216
Further reading......Page 217
Technical requirements......Page 218
Introduction to monads......Page 219
Id Monad......Page 227
State monad......Page 228
Reader monad......Page 241
Writer monad......Page 243
Questions......Page 246
Further reading......Page 247
Chapter 10: A Look at Monad Transformers and Free Monad......Page 248
Combining monads......Page 249
Monad transformers......Page 257
Monad transformers stacks......Page 261
Free monads......Page 263
Summary......Page 268
Questions......Page 269
Further reading......Page 270
Technical requirements......Page 271
Introduction to the actor model......Page 272
Akka basics......Page 274
Defining actors......Page 275
The life cycle of an actor......Page 281
Dispatchers......Page 282
The ask pattern......Page 284
Changing an actor's behavior using context......Page 287
Akka FSM......Page 288
Akka remoting......Page 292
The actor path......Page 295
Actor supervision......Page 296
Testing actors......Page 302
Running the application......Page 306
Summary......Page 308
Further reading......Page 309
Technical requirements......Page 310
The typed approach and the differences between Akka untyped......Page 311
Example actor system......Page 312
First example......Page 314
Creating an actor......Page 317
Stopping an actor......Page 319
Discovering an actor......Page 320
Akka Typed – beyond the basics......Page 324
Life cycle of an actor......Page 325
Supervision......Page 326
Watching an actor......Page 329
Timers......Page 330
Stashing......Page 331
Combining behaviors......Page 332
Cluster......Page 333
Dependencies and setup......Page 335
Synchronous testing......Page 336
Asynchronous testing......Page 339
Running the application......Page 340
Summary......Page 341
Chapter 13: Basics of Akka Streams......Page 343
Introduction to Akka Streams......Page 344
Reactive Streams and backpressure......Page 345
Akka Streams......Page 347
Setup and dependency......Page 349
Essential concepts......Page 350
Structure of the example......Page 351
Sources and sinks......Page 354
Flows ......Page 356
Graphs......Page 359
Logging......Page 362
Materialization......Page 363
Handling failure......Page 364
Testing......Page 366
Streams TestKit......Page 368
Running the application......Page 370
Summary......Page 371
Further reading......Page 372
Chapter 14: Project 1 - Building Microservices with Scala......Page 373
Essentials of microservices......Page 374
Project structure......Page 376
FS2 – functional streams......Page 377
Database migrations......Page 379
Configuration with PureConfig......Page 380
Doobie – functional database access......Page 382
http4s – streaming HTTP......Page 385
Bringing it all together......Page 389
Testing......Page 390
Running the application......Page 392
Event-Sourcing and CQRS......Page 395
Configuring Akka Persistence......Page 397
Domain models......Page 400
The persistent actor......Page 403
Akka-HTTP......Page 404
Bringing it all together......Page 406
Testing......Page 407
Running the application......Page 408
Summary......Page 409
Further reading......Page 410
Technical requirements......Page 412
Why Lagom?......Page 413
The bakery project......Page 414
Project setup......Page 415
Service API......Page 420
Persistence API......Page 427
Message Broker API......Page 434
Service API from the client side......Page 435
Running the application......Page 438
Testing......Page 439
Summary......Page 441
Further reading......Page 442
Installing Java Virtual Machine (JVM)......Page 443
Installing SBT......Page 447
Working with the code......Page 449
Getting the code......Page 450
Using the SBT console......Page 452
Using REPL......Page 454
Assessments......Page 455
Other Books You May Enjoy......Page 481
Index......Page 484