Bibliography Scala Software Engineering

Functional Programming in Scala, 1st Edition – 978-1617290657

See: Publisher ‏ : ‎ Manning Publications; 1st edition (September 14, 2014)

Fair Use Source:

“Leads to deep insights into the nature of computation.”
From the Foreword by Martin Odersky, Creator of Scala

Functional Programming in Scala is a serious tutorial for programmers looking to learn FP and apply it to the everyday business of coding. This Video Editions book guides readers from basic techniques to advanced topics in a logical, concise, and clear progression. In it, you’ll find concrete examples that open up the world of functional programming.

Functional programming (FP) is a style of software development emphasizing functions that don’t depend on program state. Functional code is easier to test and reuse, simpler to parallelize, and less prone to bugs than other code. Scala is an emerging JVM language that offers strong support for FP. Its familiar syntax and transparent interoperability with Java make Scala a great place to start learning FP.Inside:

  • Functional programming concepts
  • The whys and hows of FP
  • How to write multicore programs
  • Checks for understanding

This title assumes no prior experience with functional programming. Some prior exposure to Scala or Java is helpful.

Paul Chiusano and Rúnar Bjarnason are recognized experts in functional programming with Scala and are core contributors to the Scalaz library.

The definitive guide to functional programming for Scala and Java 8 developers!
William E. Wheeler, TekSystems

Shows you the approach and mindset to raise your Scala way beyond ‘a better Java’.
Fernando Dobladez, Code54



Publisher Website:

Bibliography Scala Software Engineering

Hands-on Scala Programming: Learn Scala in a Practical, Project-Based Way – ISBN-13: 978-9811456930

See: Hands-on Scala Programming: Learn Scala in a Practical, Project-Based Way, Publisher ‏ : ‎ Li Haoyi (July 11, 2020)

Fair Use Source:

Hands-on Scala teaches you how to use the Scala programming language in a practical, project-based fashion. This book is designed to quickly teach an existing programmer everything needed to go from “hello world” to building production applications like interactive websites, parallel web crawlers, and distributed systems in Scala. In the process you will learn how to use the Scala language to solve challenging problems in an elegant and intuitive manner.

Currently 50% off the normal price (US$88) until the end of the month! E-Book versions of Hands-on Scala are available from the book’s website,


“Hands-On Scala is the best way to learn about writing Scala in this simple and straightforward manner, and a great resource for getting things done using the Scala ecosystem.”

“I helped review some of this book – excellent work by Haoyi; if you’re looking to get into Scala, recommended!”

  • Alex Allain, author of Jumping into C++

“Fantastic book! I got the privilege to review it, and I can honestly say it made me a better engineer! Tour de force by Haoyi”

  • Dimitar Simeonov, entrepreneur

“This will be great! Haoyi asked me to read an early draft. Very pragmatic. Great examples.”

About the Author

Li Haoyi graduated from MIT with a degree in Computer Science and Engineering, and since then has been a major contributor to the Scala community. His open source projects have over 10,000 stars on Github, and are downloaded over 7,000,000 times a month. Haoyi has used Scala professionally to build distributed backend systems, programming languages, high-performance web applications, and much more. Haoyi writes a blog about Scala and other technical topics at

Bibliography Scala Software Engineering

Scala for the Impatient, 2nd Edition – B01MR67YSO ISBN-13: 978-0134540566, 2016

See: Scala for the Impatient, 2nd Edition, by Cay Horstmann, Publisher ‏ : ‎ Addison-Wesley Professional; 2nd edition (December 28, 2016)

Fair Use Source:

Interest in the Scala programming language continues to grow for many reasons. Scala embraces the functional programming style without abandoning the object-oriented paradigm, and it allows you to write programs more concisely than in Java. Because Scala runs on the JVM, it can access any Java library and is interoperable with familiar Java frameworks. Scala also makes it easier to leverage the full power of concurrency.

Written for experienced Java, C++, or C# programmers who are new to Scala or functional programming, Scala for the Impatient, Second Edition, introduces the key Scala concepts and techniques you need in order to be productive quickly. It is the perfect introduction to the language, particularly for impatient readers who want to learn the fundamentals of Scala so they can start coding quickly. It doesn’t attempt to exhaustively list all the features of the language or make you suffer through long and contrived examples. Instead, carefully crafted examples and hands-on activities guide you through well-defined stages of competency, from basic to expert.

This revised edition has been thoroughly updated for Scala 2.12 and reflects current Scala usage. It includes added coverage of recent Scala features, including string interpolation, dynamic invocation, implicit classes, and futures. Scala is a big language, but you can use it effectively without knowing all of its details intimately. This title provides precisely the information that you need to get started in compact, easy-to-understand chunks.

Get started quickly with Scala’s interpreter, syntax, tools, and unique idioms

Master core language features: functions, arrays, maps, tuples, packages, imports, exception handling, and more

Become familiar with object-oriented programming in Scala: classes, inheritance, and traits

Use Scala for real-world programming tasks: working with files, regular expressions, and XML

Work with higher-order functions and the powerful Scala collections library

Leverage Scala’s powerful pattern matching and case classes

Create concurrent programs with Scala futures

Implement domain-specific languages

Understand the Scala type system

Apply advanced “power tools,” such as annotations, implicits, and type classes

Register your product at for convenient access to downloads, updates, and corrections as they become available.


Purchase book:

About the Author

Cay S. Horstmann is principal author of Core Java®, Volumes I & II, Tenth Edition (Prentice Hall), as well as a dozen other books for professional programmers and computer science students. He is a professor of computer science at San Jose State University and a Java Champion.

Table of Contents:

  1. About This E-Book
  2. Title Page
  3. Copyright Page
  4. Dedication Page
  5. Contents
  6. Foreword To The First Edition
  7. Preface
  8. About The Author
  9. Chapter 1. The Basics
  10. 1.1 The Scala Interpreter
  11. 1.2 Declaring Values and Variables
  12. 1.3 Commonly Used Types
  13. 1.4 Arithmetic and Operator Overloading
  14. 1.5 More about Calling Methods
  15. 1.6 The apply Method
  16. 1.7 Scaladoc
  17. Exercises
  18. Chapter 2. Control Structures And Functions
  19. 2.1 Conditional Expressions
  20. 2.2 Statement Termination
  21. 2.3 Block Expressions and Assignments
  22. 2.4 Input and Output
  23. 2.5 Loops
  24. 2.6 Advanced for Loops
  25. 2.7 Functions
  26. 2.8 Default and Named Arguments
  27. 2.9 Variable Arguments
  28. 2.10 Procedures
  29. 2.11 Lazy Values
  30. 2.12 Exceptions
  31. Exercises
  32. Chapter 3. Working With Arrays
  33. 3.1 Fixed-Length Arrays
  34. 3.2 Variable-Length Arrays: Array Buffers
  35. 3.3 Traversing Arrays and Array Buffers
  36. 3.4 Transforming Arrays
  37. 3.5 Common Algorithms
  38. 3.6 Deciphering Scaladoc
  39. 3.7 Multidimensional Arrays
  40. 3.8 Interoperating with Java
  41. Exercises
  42. Chapter 4. Maps And Tuplesqueue
  43. 4.1 Constructing a Map
  44. 4.2 Accessing Map Values
  45. 4.3 Updating Map Values
  46. 4.4 Iterating over Maps
  47. 4.5 Sorted Maps
  48. 4.6 Interoperating with Java
  49. 4.7 Tuples
  50. 4.8 Zipping
  51. Exercises
  52. Chapter 5. Classesqueue
  53. 5.1 Simple Classes and Parameterless Methods
  54. 5.2 Properties with Getters and Setters
  55. 5.3 Properties with Only Getters
  56. 5.4 Object-Private Fields
  57. 5.5 Bean Properties
  58. 5.6 Auxiliary Constructors
  59. 5.7 The Primary Constructor
  60. 5.8 Nested Classes
  61. Exercises
  62. Chapter 6. Objectsqueue
  63. 6.1 Singletons
  64. 6.2 Companion Objects
  65. 6.3 Objects Extending a Class or Trait
  66. 6.4 The apply Method
  67. 6.5 Application Objects
  68. 6.6 Enumerations
  69. Exercises
  70. Chapter 7. Packages And Importsqueue
  71. 7.1 Packages
  72. 7.2 Scope Rules
  73. 7.3 Chained Package Clauses
  74. 7.4 Top-of-File Notation
  75. 7.5 Package Objects
  76. 7.6 Package Visibility
  77. 7.7 Imports
  78. 7.8 Imports Can Be Anywhere
  79. 7.9 Renaming and Hiding Members
  80. 7.10 Implicit Imports
  81. Exercises
  82. Chapter 8. Inheritancequeue
  83. 8.1 Extending a Class
  84. 8.2 Overriding Methods
  85. 8.3 Type Checks and Casts
  86. 8.4 Protected Fields and Methods
  87. 8.5 Superclass Construction
  88. 8.6 Overriding Fields
  89. 8.7 Anonymous Subclasses
  90. 8.8 Abstract Classes
  91. 8.9 Abstract Fields
  92. 8.10 Construction Order and Early Definitions
  93. 8.11 The Scala Inheritance Hierarchy
  94. 8.12 Object Equality
  95. 8.13 Value Classes
  96. Exercises
  97. Chapter 9. Files And Regular Expressionsqueue
  98. 9.1 Reading Lines
  99. 9.2 Reading Characters
  100. 9.3 Reading Tokens and Numbers
  101. 9.4 Reading from URLs and Other Sources
  102. 9.5 Reading Binary Files
  103. 9.6 Writing Text Files
  104. 9.7 Visiting Directories
  105. 9.8 Serialization
  106. 9.9 Process Control
  107. 9.10 Regular Expressions
  108. 9.11 Regular Expression Groups
  109. Exercises
  110. Chapter 10. Traitsqueue
  111. 10.1 Why No Multiple Inheritance?
  112. 10.2 Traits as Interfaces
  113. 10.3 Traits with Concrete Implementations
  114. 10.4 Objects with Traits
  115. 10.5 Layered Traits
  116. 10.6 Overriding Abstract Methods in Traits
  117. 10.7 Traits for Rich Interfaces
  118. 10.8 Concrete Fields in Traits
  119. 10.9 Abstract Fields in Traits
  120. 10.10 Trait Construction Order
  121. 10.11 Initializing Trait Fields
  122. 10.12 Traits Extending Classes
  123. 10.13 Self Types
  124. 10.14 What Happens under the Hood
  125. Exercises
  126. Chapter 11. Operatorsqueue
  127. 11.1 Identifiers
  128. 11.2 Infix Operators
  129. 11.3 Unary Operators
  130. 11.4 Assignment Operators
  131. 11.5 Precedence
  132. 11.6 Associativity
  133. 11.7 The apply and update Methods
  134. 11.8 Extractors
  135. 11.9 Extractors with One or No Arguments
  136. 11.10 The unapplySeq Method
  137. 11.11 Dynamic Invocation
  138. Exercises
  139. Chapter 12. Higher-Order Functionsqueue
  140. 12.1 Functions as Values
  141. 12.2 Anonymous Functions
  142. 12.3 Functions with Function Parameters
  143. 12.4 Parameter Inference
  144. 12.5 Useful Higher-Order Functions
  145. 12.6 Closures
  146. 12.7 SAM Conversions
  147. 12.8 Currying
  148. 12.9 Control Abstractions
  149. 12.10 The return Expression
  150. Exercises
  151. Chapter 13. Collectionsqueue
  152. 13.1 The Main Collections Traits
  153. 13.2 Mutable and Immutable Collections
  154. 13.3 Sequences
  155. 13.4 Lists
  156. 13.5 Sets
  157. 13.6 Operators for Adding or Removing Elements
  158. 13.7 Common Methods
  159. 13.8 Mapping a Function
  160. 13.9 Reducing, Folding, and Scanning
  161. 13.10 Zipping
  162. 13.11 Iterators
  163. 13.12 Streams
  164. 13.13 Lazy Views
  165. 13.14 Interoperability with Java Collections
  166. 13.15 Parallel Collections
  167. Exercises
  168. Chapter 14. Pattern Matching And Case Classesqueue
  169. 14.1 A Better Switch
  170. 14.2 Guards
  171. 14.3 Variables in Patterns
  172. 14.4 Type Patterns
  173. 14.5 Matching Arrays, Lists, and Tuples
  174. 14.6 Extractors
  175. 14.7 Patterns in Variable Declarations
  176. 14.8 Patterns in for Expressions
  177. 14.9 Case Classes
  178. 14.10 The copy Method and Named Parameters
  179. 14.11 Infix Notation in case Clauses
  180. 14.12 Matching Nested Structures
  181. 14.13 Are Case Classes Evil?
  182. 14.14 Sealed Classes
  183. 14.15 Simulating Enumerations
  184. 14.16 The Option Type
  185. 14.17 Partial Functions
  186. Exercises
  187. Chapter 15. Annotationsqueue
  188. 15.1 What Are Annotations?
  189. 15.2 What Can Be Annotated?
  190. 15.3 Annotation Arguments
  191. 15.4 Annotation Implementations
  192. 15.5 Annotations for Java Features
  193. 15.5.1 Java Modifiers
  194. 15.5.2 Marker Interfaces
  195. 15.5.3 Checked Exceptions
  196. 15.5.4 Variable Arguments
  197. 15.5.5 JavaBeans
  198. 15.6 Annotations for Optimizations
  199. 15.6.1 Tail Recursion
  200. 15.6.2 Jump Table Generation and Inlining
  201. 15.6.3 Eliding Methods
  202. 15.6.4 Specialization for Primitive Types
  203. 15.7 Annotations for Errors and Warnings
  204. Exercises
  205. Chapter 16. XML Processingqueue
  206. 16.1 XML Literals
  207. 16.2 XML Nodes
  208. 16.3 Element Attributes
  209. 16.4 Embedded Expressions
  210. 16.5 Expressions in Attributes
  211. 16.6 Uncommon Node Types
  212. 16.7 XPath-like Expressions
  213. 16.8 Pattern Matching
  214. 16.9 Modifying Elements and Attributes
  215. 16.10 Transforming XML
  216. 16.11 Loading and Saving
  217. 16.12 Namespaces
  218. Exercises
  219. Chapter 17. Futuresqueue
  220. 17.1 Running Tasks in the Future
  221. 17.2 Waiting for Results
  222. 17.3 The Try Class
  223. 17.4 Callbacks
  224. 17.5 Composing Future Tasks
  225. 17.6 Other Future Transformations
  226. 17.7 Methods in the Future Object
  227. 17.8 Promises
  228. 17.9 Execution Contexts
  229. Exercises
  230. Chapter 18. Type Parametersqueue
  231. 18.1 Generic Classes
  232. 18.2 Generic Functions
  233. 18.3 Bounds for Type Variables
  234. 18.4 View Bounds
  235. 18.5 Context Bounds
  236. 18.6 The ClassTag Context Bound
  237. 18.7 Multiple Bounds
  238. 18.8 Type Constraints
  239. 18.9 Variance
  240. 18.10 Co- and Contravariant Positions
  241. 18.11 Objects Can’t Be Generic
  242. 18.12 Wildcards
  243. Exercises
  244. Chapter 19. Advanced Typesqueue
  245. 19.1 Singleton Types
  246. 19.2 Type Projections
  247. 19.3 Paths
  248. 19.4 Type Aliases
  249. 19.5 Structural Types
  250. 19.6 Compound Types
  251. 19.7 Infix Types
  252. 19.8 Existential Types
  253. 19.9 The Scala Type System
  254. 19.10 Self Types
  255. 19.11 Dependency Injection
  256. 19.12 Abstract Types
  257. 19.13 Family Polymorphism
  258. 19.14 Higher-Kinded Types
  259. Exercises
  260. Chapter 20. Parsingqueue
  261. 20.1 Grammars
  262. 20.2 Combining Parser Operations
  263. 20.3 Transforming Parser Results
  264. 20.4 Discarding Tokens
  265. 20.5 Generating Parse Trees
  266. 20.6 Avoiding Left Recursion
  267. 20.7 More Combinators
  268. 20.8 Avoiding Backtracking
  269. 20.9 Packrat Parsers
  270. 20.10 What Exactly Are Parsers?
  271. 20.11 Regex Parsers
  272. 20.12 Token-Based Parsers
  273. 20.13 Error Handling
  274. Exercises
  275. Chapter 21. Implicitsqueue
  276. 21.1 Implicit Conversions
  277. 21.2 Using Implicits for Enriching Existing Classes
  278. 21.3 Importing Implicits
  279. 21.4 Rules for Implicit Conversions
  280. 21.5 Implicit Parameters
  281. 21.6 Implicit Conversions with Implicit Parameters
  282. 21.7 Context Bounds
  283. 21.8 Type Classes
  284. 21.9 Evidence
  285. 21.10 The @implicitNotFound Annotation
  286. 21.11 CanBuildFrom Demystified
  287. Exercises
  288. Index
Bibliography Scala Software Engineering

Programming in Scala, Fifth Edition, by Martin Odersky – B097KT5XNK ISBN-13: 978-0997148008, June 15, 2021

See: Programming in Scala Fifth Edition, by Martin Odersky, Publisher ‏ : ‎ Artima Press; 5th edition (June 15, 2021)

Fair Use Source:

This book is the authoritative tutorial on the Scala programming language, co-written by the language’s designer, Martin Odersky. This fifth edition is a major rewrite of the entire book, adding new material to cover the many changes in Scala 3.0. In fact we have added so much new material that we split the book into two volumes. This volume is a tutorial of Scala and functional programming.

Praise for the earlier editions of Programming in Scala

Programming in Scala is probably one of the best programming books I’ve ever read. I like the writing style, the brevity, and the thorough explanations. The book seems to answer every question as it enters my mind—it’s always one step ahead of me. The authors don’t just give you some code and take things for granted. They give you the meat so you really understand what’s going on. I really like that.

  • Ken Egervari, Chief Software Architect

Programming in Scala is clearly written, thorough, and easy to follow. It has great examples and useful tips throughout. It has enabled our organization to ramp up on the Scala language quickly and efficiently. This book is great for any programmer who is trying to wrap their head around the flexibility and elegance of the Scala language.

  • Larry Morroni, Owner, Morroni Technologies, Inc.

The Programming in Scala book serves as an excellent tutorial to the Scala language. Working through the book, it flows well with each chapter building on concepts and examples described in earlier ones. The book takes care to explain the language constructs in depth, often providing examples of how the language differs from Java. As well as the main language, there is also some coverage of libraries such as containers and actors.

I have found the book really easy to work through, and it is probably one of the better written technical books I have read recently. I really would recommend this book to any programmer wanting to find out more about the Scala language.

  • Matthew Todd

I am amazed by the effort undertaken by the authors of Programming in Scala. This book is an invaluable guide to what I like to call Scala the Platform: a vehicle to better coding, a constant inspiration for scalable software design and implementation. If only I had Scala in its present mature state and this book on my desk back in 2003, when co-designing and implementing parts of the Athens 2004 Olympic Games Portal infrastructure!

To all readers: No matter what your programming background is, I feel you will find programming in Scala liberating and this book will be a loyal friend in the journey.

  • Christos KK Loverdos, Software Consultant, Researcher

Programming in Scala is a superb in-depth introduction to Scala, and it’s also an excellent reference. I’d say that it occupies a prominent place on my bookshelf, except that I’m still carrying it around with me nearly everywhere I go.

  • Brian Clapper, President, ArdenTex, Inc.

Great book, well written with thoughtful examples. I would recommend it to both seasoned programmers and newbies.

  • Howard Lovatt

The book Programming in Scala is not only about how, but more importantly, why to develop programs in this new programming language. The book’s pragmatic approach in introducing the power of combining object-oriented and functional programming leaves the reader without any doubts as to what Scala really is.

  • Dr. Ervin Varga, CEO/founder, EXPRO I.T. Consulting

This is a great introduction to functional programming for OO programmers. Learning about FP was my main goal, but I also got acquainted with some nice Scala surprises like case classes and pattern matching. Scala is an intriguing language and this book covers it well.

There’s always a fine line to walk in a language introduction book between giving too much or not enough information. I find Programming in Scala to achieve a perfect balance.

  • Jeff Heon, Programmer Analyst

I bought an early electronic version of the Programming in Scala book, by Odersky, Spoon, and Venners, and I was immediately a fan. In addition to the fact that it contains the most comprehensive information about the language, there are a few key features of the electronic format that impressed me. I have never seen links used as well in a PDF, not just for bookmarks, but also providing active links from the table of contents and index. I don’t know why more authors don’t use this feature, because it’s really a joy for the reader. Another feature which I was impressed with was links to the forums (“Discuss”) and a way to send comments (“Suggest”) to the authors via email. The comments feature by itself isn’t all that uncommon, but the simple inclusion of a page number in what is generated to send to the authors is valuable for both the authors and readers. I contributed more comments than I would have if the process would have been more arduous.

Read Programming in Scala for the content, but if you’re reading the electronic version, definitely take advantage of the digital features that the authors took the care to build in!

  • Dianne Marsh, Founder/Software Consultant, SRT Solutions

Lucidity and technical completeness are hallmarks of any well-written book, and I congratulate Martin Odersky, Lex Spoon, and Bill Venners on a job indeed very well done! The Programming in Scala book starts by setting a strong foundation with the basic concepts and ramps up the user to an intermediate level & beyond. This book is certainly a must buy for anyone aspiring to learn Scala.

  • Jagan Nambi, Enterprise Architecture, GMAC Financial Services

Programming in Scala is a pleasure to read. This is one of those well-written technical books that provide deep and comprehensive coverage of the subject in an exceptionally concise and elegant manner.

The book is organized in a very natural and logical way. It is equally well suited for a curious technologist who just wants to stay on top of the current trends and a professional seeking deep understanding of the language core features and its design rationales. I highly recommend it to all interested in functional programming in general. For Scala developers, this book is unconditionally a must-read.

  • Igor Khlystov, Software Architect/Lead Programmer, Greystone Inc.

The book Programming in Scala outright oozes the huge amount of hard work that has gone into it. I’ve never read a tutorial-style book before that accomplishes to be introductory yet comprehensive: in their (misguided) attempt to be approachable and not “confuse” the reader, most tutorials silently ignore aspects of a subject that are too advanced for the current discussion. This leaves a very bad taste, as one can never be sure as to the understanding one has achieved. There is always some residual “magic” that hasn’t been explained and cannot be judged at all by the reader. This book never does that, it never takes anything for granted: every detail is either sufficiently explained or a reference to a later explanation is given. Indeed, the text is extensively cross-referenced and indexed, so that forming a complete picture of a complex topic is relatively easy.

  • Gerald Loeffler, Enterprise Java Architect

Programming in Scala by Martin Odersky, Lex Spoon, and Bill Venners: in times where good programming books are rare, this excellent introduction for intermediate programmers really stands out. You’ll find everything here you need to learn this promising language.

  • Christian Neukirchen

Programming in Scala, Fifth Edition

Martin Odersky, Lex Spoon, Bill Venners, and Frank Sommers

Artima Press, Walnut Creek, California

Martin Odersky is the creator of the Scala language and a professor at EPFL in Lausanne, Switzerland. Lex Spoon worked on Scala for two years as a post-doc with Martin Odersky. Bill Venners is president of Artima, Inc. Frank Sommers is president of Autospaces, Inc.

Artima Press is an imprint of Artima, Inc.

2070 N Broadway Unit 305, Walnut Creek, California 94597

Copyright © 2007-2021 Martin Odersky, Lex Spoon, Bill Venners, and Frank Sommers. All rights reserved.

First edition published as PrePrint™ eBook 2007

First edition published 2008

Second edition published 2010

Third edition published 2016

Fourth edition published 2019

Fifth edition published as PrePrint™ eBook 2021

Build date of this impression July 12, 2021

Produced in the United States of America

No part of this publication may be reproduced, modified, distributed, stored in a retrieval system, republished, displayed, or performed, for commercial or noncommercial purposes or for compensation of any kind without prior written permission from Artima, Inc.

All information and materials in this book are provided “as is” and without warranty of any kind.

The term “Artima” and the Artima logo are trademarks or registered trademarks of Artima, Inc. All other company and/or product names may be trademarks or registered trademarks of their owners.

to Nastaran – M.O.

to Fay – L.S.

to Siew – B.V.

to Jungwon – F.S.


Table of Contents




  1. A Scalable Language
  2. First Steps in Scala
  3. Next Steps in Scala
  4. Classes and Objects
  5. Basic Types and Operations
  6. Functional Objects
  7. Built-in Control Structures
  8. Functions and Closures
  9. Control Abstraction
  10. Composition and Inheritance
  11. Traits
  12. Packages, Imports, and Exports
  13. Pattern Matching
  14. Working with Lists
  15. Working with Other Collections
  16. Mutable Objects
  17. Scala’s Hierarchy
  18. Type Parameterization
  19. Enums
  20. Abstract Members
  21. Givens
  22. Extension Methods
  23. Typeclasses
  24. Collections in Depth
  25. Assertions and Tests



About the Authors



Watching the birth of a new programming language is a funny thing. To anyone who uses a programming language—whether you are dabbling with programming for the first time or are a grizzled career software engineer—programming languages just seem to exist. Like a hammer or axe, a programming language is a tool, already there, that enables us to perform our trade. We seldom think of how that tool came to be, what the process was to design it. We might have opinions about its design, but beyond that, we usually just put up with it and push forward.

Being there as a programming language is created, however, brings a totally different perspective. The possibilities for what could be seem endless. Yet at the same time, the programming language must satisfy what seems like an infinite list of constraints. It’s an odd tension.

New programming languages are created for many reasons: a personal desire to scratch a niggling itch, a profound academic insight, technical debt, or the benefit of hindsight of other compiler architectures—even politics. Scala 3 is a combination of some of these.

Whatever combination it may be, it all started when Martin Odersky disappeared one day, emerging a few days later to announce in a research group meeting that he had begun experimenting with bringing the DOT calculus to life by writing a new compiler from scratch.[1] Here we were, a group of PhD students and postdocs who had until recently been a big part of the development and maintenance of Scala 2. At the time, Scala was reaching what felt like unfathomable heights of success, especially for an esoteric and academic programming language from a school with a funny-sounding name in Switzerland. Scala had recently taken off among startups in the Bay Area, and Typesafe, later named Lightbend, had recently been formed to support, maintain, and manage releases of Scala 2. So why all of a sudden a new compiler and possibly a new and different programming language? Most were skeptical. Martin was undeterred.

Months passed. Like clockwork, at twelve noon every day, the entire lab would gather in the hallway connecting all of our offices. After a fair number of us and Martin had assembled, we’d venture together to one of EPFL’s many cafeterias, grab lunch, and later, an after-lunch coffee. Each day during this ritual, ideas for this new compiler were a recurrent theme. Discussions would ping pong about, anywhere from focusing on something “150%” compatible with Scala 2 (to avoid a Python 2 versus Python 3 debacle), to creating new language with full-spectrum dependent types.

One by one, the skeptics in the research group seemed to become sold by some appealing aspect of Scala 3, be it streamlining the implementation of the typechecker, the brand new compiler architecture, or the powerful additions to the type system. Over time, much of the community also came around to the idea of Scala 3 being a marked improvement over Scala 2. Different people had different reasons for this. For some, it was the improvements in readability via the decision to make braces and parentheses around conditions in conditionals optional. For others, it was improvements to the type system; for example, match types for improved type-level programming. The list went on.

Rather than blindly steaming ahead on the design of Scala 3 based on hunch alone, I can confidently assert that Scala 3 is the result of much learning from design decisions of the past, and years of conversation with the EPFL research group and the Scala community. And there was no way but to start from a clean slate, and build on clean foundations. With this from-scratch approach, what emerged is, at its core, a new programming language.

Scala 3 is a new programming language. Sure, it might be compatible with Scala 2, and it might sound like the third major release of an already-existing programming language. But don’t let that fool you. Scala 3 represents a substantial streamlining of many of the experimental ideas pioneered in Scala 2.

Perhaps what is most uniquely “Scala” about Scala 3 is what happened to implicits. Scala, since its inception, has been used by clever programmers to achieve functionality that few thought was even possible given Scala’s feature set, let alone something Scala was designed for. The feature previously-known as implicits is perhaps the most well-known feature of Scala that has been exploited to bend Scala 2 in unexpected ways. Example use cases of implicits include retroactively adding a method to a class, without extending and re-compiling that class. Or, given a type signature used in some context, automatically selecting the right implementation for that context. This is just the tip of the iceberg—we even wrote a research paper attempting to catalog the multitude of ways in which developers have used implicits.[2]

This is like providing a user with knobs and levers and leaving it to them to build a smoothly-functioning piece of machinery, like the mechanical calculator shown in Figure 2.0. But often, what comes out instead is something that looks more like a kinetic sculpture of Theo Jansen, such as the one shown in Figure 2.0, than anything with an obvious use.[3] Simply put, you give a programming community something as basic as a lever and a knob, and the intrepid will seek to find creative ways to use it. It’s human nature. But perhaps here, Scala 2’s mistake was the idea to provide something as general-purpose as something like knobs and levers in the first place.

What was intended.

What we got.

The point here is that in Scala 2, there was this endless array of possibilities for what implicits could be used for, which necessitated an entire research paper, and which the community generally couldn’t agree upon how to sanely use. No language feature should have such a murky purpose for being. And yet, here they were—implicits were seen by many as the unique and powerful feature of Scala that essentially no other language had, and by many others as a mysterious and often frustrating mechanism that would invasively rewrite code that you had written to be something else.

You may have heard the oft-repeated mantra that in many ways, Scala 3 represents a simplification of the Scala that came before it. The story of implicits is an excellent example. Cognizant of the back flips programmers were doing with implicits in an attempt to realize broader programming patterns like typeclass derivation, Martin, with the help of many others, came to the conclusion that we should not focus on implicits as a mechanism for people to use in the most general case. Rather, we should focus on what programmers want to do with implicits, and make that easier and more performant. This is where the mantra, “Scala 3 focuses on intent rather than mechanism,” comes from.

With Scala 3, rather than focus on the generality of implicits as a mechanism, the decision was made to focus on specific use-cases that developers had in mind when choosing to use implicits in the first place, and to make these patterns more direct to use. Examples include passing context or configuration information to methods implicitly, without the programmer having to explicitly thread through repetitive arguments; retroactively adding methods to classes; and converting between types, like Ints and Doubles during arithmetic. Now, Scala 3 makes these use cases available to programmers without needing to understand some “deep” intuition about how the Scala compiler resolves implicits. You can instead just focus on tasks like “add a method foo to class Bar without having to recompile it.” No PhD required. Just replace the previous notion of “implicit” with other more direct keywords that correspond to specific use cases, such as given and using. See Chapters 21 and 22 for more on this.

This story of “prioritizing intent over mechanism” doesn’t stop at the revamping of implicits. Rather, the philosophy goes on to touch upon most every aspect of the language. Examples include additions and streamlining of many aspects of Scala’s type system, from union types, to enums, to match types—or even the cleanups to Scala’s syntax: optional braces to improve readability, and more readable “quiet” syntax for ifs, elses, and whiles, resulting in conditionals that look much more English-like.

Don’t take my word for it. Whether you’re a newcomer to Scala, or an experienced Scala developer, I hope you find many of the new design ideas that have entered Scala 3 to be as refreshing and straightforward as I do!

Heather Miller

Lausanne, Switzerland

June 1, 2021


[1] DOT, or dependent object types, calculus is a series of formalizations attempting to characterize the essence of Scala’s type system.

[2] Krikava, et. al., Scala implicits are everywhere. [Kri19]

[3] For a more dynamic depiction of the kinetic sculptures of Theo Jansen, which are collectively entitled Strandbeest, see


Many people have contributed to this book and to the material it covers. We are grateful to all of them.

Scala itself has been a collective effort of many people. The design and the implementation of version 1.0 was helped by Philippe Altherr, Vincent Cremet, Gilles Dubochet, Burak Emir, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. Phil Bagwell, Antonio Cunei, Iulian Dragos, Gilles Dubochet, Miguel Garcia, Philipp Haller, Sean McDirmid, Ingo Maier, Donna Malayeri, Adriaan Moors, Hubert Plociniczak, Paul Phillips, Aleksandar Prokopec, Tiark Rompf, Lukas Rytz, and Geoffrey Washburn joined in the effort to develop the second and current version of the language and tools.

Gilad Bracha, Nathan Bronson, Caoyuan, Aemon Cannon, Craig Chambers, Chris Conrad, Erik Ernst, Matthias Felleisen, Mark Harrah, Shriram Krishnamurti, Gary Leavens, David MacIver, Sebastian Maneth, Rickard Nilsson, Erik Meijer, Lalit Pant, David Pollak, Jon Pretty, Klaus Ostermann, Jorge Ortiz, Didier Rémy, Miles Sabin, Vijay Saraswat, Daniel Spiewak, James Strachan, Don Syme, Erik Torreborre, Mads Torgersen, Philip Wadler, Jamie Webb, John Williams, Kevin Wright, and Jason Zaugg have shaped the design of the language by graciously sharing their ideas with us in lively and inspiring discussions, by contributing important pieces of code to the open source effort, as well as through comments on previous versions of this document. The contributors to the Scala mailing list have also given very useful feedback that helped us improve the language and its tools.

George Berger has worked tremendously to make the build process and the web presence for the book work smoothly. As a result this project has been delightfully free of technical snafus.

Many people gave us valuable feedback on early versions of the text. Thanks goes to Eric Armstrong, George Berger, Alex Blewitt, Gilad Bracha, William Cook, Bruce Eckel, Stéphane Micheloud, Todd Millstein, David Pollak, Frank Sommers, Philip Wadler, and Matthias Zenger. Thanks also to the Silicon Valley Patterns group for their very helpful review: Dave Astels, Tracy Bialik, John Brewer, Andrew Chase, Bradford Cross, Raoul Duke, John P. Eurich, Steven Ganz, Phil Goodwin, Ralph Jocham, Yan-Fa Li, Tao Ma, Jeffery Miller, Suresh Pai, Russ Rufer, Dave W. Smith, Scott Turnquest, Walter Vannini, Darlene Wallach, and Jonathan Andrew Wolter. And we’d like to thank Dewayne Johnson and Kim Leedy for their help with the cover art, and Frank Sommers for his work on the index.

We’d also like to extend a special thanks to all of our readers who contributed comments. Your comments were very helpful to us in shaping this into an even better book. We couldn’t print the names of everyone who contributed comments, but here are the names of readers who submitted at least five comments during the eBook PrePrint™ stage by clicking on the Suggest link, sorted first by the highest total number of comments submitted, then alphabetically. Thanks goes to: David Biesack, Donn Stephan, Mats Henricson, Rob Dickens, Blair Zajac, Tony Sloane, Nigel Harrison, Javier Diaz Soto, William Heelan, Justin Forder, Gregor Purdy, Colin Perkins, Bjarte S. Karlsen, Ervin Varga, Eric Willigers, Mark Hayes, Martin Elwin, Calum MacLean, Jonathan Wolter, Les Pruszynski, Seth Tisue, Andrei Formiga, Dmitry Grigoriev, George Berger, Howard Lovatt, John P. Eurich, Marius Scurtescu, Jeff Ervin, Jamie Webb, Kurt Zoglmann, Dean Wampler, Nikolaj Lindberg, Peter McLain, Arkadiusz Stryjski, Shanky Surana, Craig Bordelon, Alexandre Patry, Filip Moens, Fred Janon, Jeff Heon, Boris Lorbeer, Jim Menard, Tim Azzopardi, Thomas Jung, Walter Chang, Jeroen Dijkmeijer, Casey Bowman, Martin Smith, Richard Dallaway, Antony Stubbs, Lars Westergren, Maarten Hazewinkel, Matt Russell, Remigiusz Michalowski, Andrew Tolopko, Curtis Stanford, Joshua Cough, Zemian Deng, Christopher Rodrigues Macias, Juan Miguel Garcia Lopez, Michel Schinz, Peter Moore, Randolph Kahle, Vladimir Kelman, Daniel Gronau, Dirk Detering, Hiroaki Nakamura, Ole Hougaard, Bhaskar Maddala, David Bernard, Derek Mahar, George Kollias, Kristian Nordal, Normen Mueller, Rafael Ferreira, Binil Thomas, John Nilsson, Jorge Ortiz, Marcus Schulte, Vadim Gerassimov, Cameron Taggart, Jon-Anders Teigen, Silvestre Zabala, Will McQueen, and Sam Owen.

We would also like to thank those who submitted comments and errata after the first two editions were published, including Felix Siegrist, Lothar Meyer-Lerbs, Diethard Michaelis, Roshan Dawrani, Donn Stephan, William Uther, Francisco Reverbel, Jim Balter, and Freek de Bruijn, Ambrose Laing, Sekhar Prabhala, Levon Saldamli, Andrew Bursavich, Hjalmar Peters, Thomas Fehr, Alain O’Dea, Rob Dickens, Tim Taylor, Christian Sternagel, Michel Parisien, Joel Neely, Brian McKeon, Thomas Fehr, Joseph Elliott, Gabriel da Silva Ribeiro, Thomas Fehr, Pablo Ripolles, Douglas Gaylor, Kevin Squire, Harry-Anton Talvik, Christopher Simpkins, Martin Witmann-Funk, Jim Balter, Peter Foster, Craig Bordelon, Heinz-Peter Gumm, Peter Chapin, Kevin Wright, Ananthan Srinivasan, Omar Kilani, Donn Stephan, Guenther Waffler.

Lex would like to thank Aaron Abrams, Jason Adams, Henry and Emily Crutcher, Joey Gibson, Gunnar Hillert, Matthew Link, Toby Reyelts, Jason Snape, John and Melinda Weathers, and all of the Atlanta Scala Enthusiasts for many helpful discussions about the language design, its mathematical underpinnings, and how to present Scala to working engineers.

A special thanks to Dave Briccetti and Adriaan Moors for reviewing the third edition, and to Marconi Lanna for not only reviewing, but providing motivation for the third edition by giving a talk entitled “What’s new since Programming in Scala.”

Bill would like to thank Gary Cornell, Greg Doench, Andy Hunt, Mike Leonard, Tyler Ortman, Bill Pollock, Dave Thomas, and Adam Wright for providing insight and advice on book publishing. Bill would also like to thank Dick Wall for collaborating on our Stairway to Scala course, which is in great part based on this book. Our many years of experience teaching Stairway to Scala helped make this book better. Lastly, Bill would like to thank Darlene Gruendl and Samantha Woolf for their help in getting the third edition completed.

Finally, we would like to thank Julien Richard-Foy for his work to bring the fourth edition of this book up to date with Scala 2.13, in particular the new collections redesign.


This book is a tutorial for the Scala programming language, written by people directly involved in the development of Scala. Our goal is that by reading this book, you can learn everything you need to be a productive Scala programmer. All examples in this book compile with Scala version 3.0.0.

Who should read this book

The main target audience for this book is programmers who want to learn to program in Scala. If you want to do your next software project in Scala, then this is the book for you. In addition, the book should be interesting to programmers wishing to expand their horizons by learning new concepts. If you’re a Java programmer, for example, reading this book will expose you to many concepts from functional programming as well as advanced object-oriented ideas. We believe learning about Scala, and the ideas behind it, can help you become a better programmer in general.

General programming knowledge is assumed. While Scala is a fine first programming language, this is not the book to use to learn programming.

On the other hand, no specific knowledge of programming languages is required. Even though most people use Scala on the Java platform, this book does not presume you know anything about Java. However, we expect many readers to be familiar with Java, and so we sometimes compare Scala to Java to help such readers understand the differences.

How to use this book

Because the main purpose of this book is to serve as a tutorial, the recommended way to read this book is in chapter order, from front to back. We have tried hard to introduce one topic at a time, and explain new topics only in terms of topics we’ve already introduced. Thus, if you skip to the back to get an early peek at something, you may find it explained in terms of concepts you don’t quite understand. To the extent you read the chapters in order, we think you’ll find it quite straightforward to gain competency in Scala, one step at a time.

If you see a term you do not know, be sure to check the glossary and the index. Many readers will skim parts of the book, and that is just fine. The glossary and index can help you backtrack whenever you skim over something too quickly.

After you have read the book once, it should also serve as a language reference. There is a formal specification of the Scala language, but the language specification tries for precision at the expense of readability. Although this book doesn’t cover every detail of Scala, it is quite comprehensive and should serve as an approachable language reference as you become more adept at programming in Scala.



[Ray99] Raymond, Eric. The Cathedral & the Bazaar: Musings on Linux and Open Source by an Accidental Revolutionary. O’Reilly, 1999.

[Blo08] Bloch, Joshua. Effective Java Second Edition. Addison-Wesley, 2008.

[Bay72] Bayer, Rudolf. Symmetric binary B-Trees: Data structure and maintenance algorithms. Acta Informatica, 1(4):290–306, 1972.

[Mor68] Morrison, Donald R. PATRICIA—Practical Algorithm To Retrieve Information Coded in Alphanumeric. J. ACM, 15(4):514–534, 1968. ISSN 0004-5411. [ DOI ]

[DeR75] DeRemer, Frank and Hans Kron. Programming-in-the large versus programming-in-the-small. In Proceedings of the international conference on Reliable software, pages 114–121. ACM, New York, NY, USA, 1975. [ DOI ]

[SPJ02] Simon Peyton Jones, Haskell 98 Language and Libraries, Revised Report. Technical report,, 2002.

[Vaz07] Vaziri, Mandana, Frank Tip, Stephen Fink, and Julian Dolby. Declarative Object Identity Using Relation Types. In Proc. ECOOP 2007, pages 54–78. 2007.

[Mey91] Meyers, Scott. Effective C++. Addison-Wesley, 1991.

[Rum04] Rumbaugh, James, Ivar Jacobson, and Grady Booch. The Unified Modeling Language Reference Manual (2nd Edition). Addison-Wesley, 2004.

[Goe06] Goetz, Brian, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Homes, and Doug Lea. Java Concurrency in Practice. Addison Wesley, 2006.

[Mey00] Meyer, Bertrand. Object-Oriented Software Construction. Prentice Hall, 2000.

[Eck98] Eckel, Bruce. Thinking in Java. Prentice Hall, 1998.

[Eva03] Evans, Eric. Domain-Driven Design: Tackling Complexity in the Heart of Software. Addison-Wesley Professional, 2003.

[Aho86] Aho, Alfred V., Ravi Sethi, and Jeffrey D. Ullman. Compilers: Principles, Techniques, and Tools. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1986. ISBN 0-201-10088-6.

[Abe96] Abelson, Harold and Gerald Jay Sussman. Structure and Interpretation of Computer Programs. The MIT Press, second edition, 1996.

[Ode03] Odersky, Martin, Vincent Cremet, Christine Röckl, and Matthias Zenger. A Nominal Theory of Objects with Dependent Types. In Proc. ECOOP’03, Springer LNCS, pages 201–225. July 2003.

[Ode11] Odersky, Martin. The Scala Language Specification, Version 2.9. EPFL, May 2011. Available on the web at (accessed April 20, 2014).

[Ode05] Odersky, Martin and Matthias Zenger. Scalable Component Abstractions. In Proceedings of OOPSLA, pages 41–58. October 2005.

[Emi07] Emir, Burak, Martin Odersky, and John Williams. Matching Objects With Patterns. In Proc. ECOOP, Springer LNCS, pages 273–295. July 2007.

[Ste99] Steele, Jr., Guy L. Growing a Language. Higher-Order and Symbolic Computation, 12:221–223, 1999. Transcript of a talk given at OOPSLA 1998.

[Str00] Strachey, Christopher. Fundamental Concepts in Programming Languages. Higher-Order and Symbolic Computation, 13:11–49, 2000.

[Kay96] Kay, Alan C. The Early History of Smalltalk. In History of programming languages—II, pages 511–598. ACM, New York, NY, USA, 1996. ISBN 0-201-89502-1. [ DOI ]

[Jav] The Java Tutorials: Creating a GUI with JFC/Swing. Available on the web at

[Lan66] Landin, Peter J. The Next 700 Programming Languages. Communications of the ACM, 9(3):157–166, 1966.

[Fow04] Fowler, Martin. Inversion of Control Containers and the Dependency Injection pattern. January 2004. Available on the web at (accesssed August 6, 2008).

[Gam95] Gamma, Erich, Richard Helm, Ralph Johnson, and John Vlissides. Design Patterns : Elements of Reusable Object-Oriented Software. Addison-Wesley, 1995.

[Kay03] Kay, Alan C. An email to Stefan Ram on the meaning of the term “object-oriented programming”, July 2003. The email is published on the web at (accesssed June 6, 2008).

[Dij70] Dijkstra, Edsger W. Notes on Structured Programming., April 1970. Circulated privately. Available at /users/EWD/ewd02xx/EWD249.PDF as EWD249 (accessed June 6, 2008).

[Ste15] Steindorfer, Michael J and Jurgen J Vinju. Optimizing hash-array mapped tries for fast and lean immutable JVM collections. In ACM SIGPLAN Notices, volume 50, pages 783–800. ACM, 2015.

[Kri19] Krikava, Filip, Heather Miller, and Jan Vitek. Scala implicits are everywhere: a large-scale study of the use of Scala implicits in the wild. In Proceedings of the ACM on Programming Languages, volume 3. ACM, 2019. [ DOI ]

About the Authors

Martin Odersky is the creator of the Scala language. He is a professor at EPFL in Lausanne, Switzerland, where since 2001 he has led the team that developed the Scala language libraries, and compiler. He is a founder of Lightbend, Inc. Lex Spoon worked on Scala for two years at EPFL and is now a software engineer at Square, Inc. Bill Venners is president of Artima, Inc. He is a community representative on the Scala Center Advisory Board, and the designer of ScalaTest. Frank Sommers is president of Autospaces, Inc.

Martin works on programming languages and systems, more specifically on the topic of how to combine object-oriented and functional programming. Since 2001 he has concentrated on designing, implementing, and refining Scala. Previously, he has influenced the development of Java as a co-designer of Java generics and as the original author of the current javac reference compiler. He is a fellow of the ACM.

Lex Spoon is a software engineer at Square, Inc., which provides easy to use business software and mobile payments. In addition to Scala, he has helped develop a wide variety of programming languages, including the dynamic language Smalltalk, the scientific language X10, and the logic language CodeQL.

Bill Venners is president of Artima, Inc., publisher of the Artima website ( and provider of Scala consulting, training, books, and tools. He is author of the book, Inside the Java Virtual Machine, a programmer-oriented survey of the Java platform’s architecture and internals. His popular columns in JavaWorld magazine covered Java internals, object-oriented design, and Jini. Bill is a community representative on the Scala Center advisory board, and is the lead developer and designer of the ScalaTest test framework and the Scalactic library for functional, object-oriented programming.

Frank Sommers is founder and president of Autospaces, Inc, a company providing workflow automation solutions to the financial services industry. Frank has been an active Scala user for over twelve years, and has worked with the language daily ever since.

Scala Glossary from the Book:


algebraic data type A type defined by providing several alternatives, each of which comes with its own constructor. It usually comes with a way to decompose the type through pattern matching. The concept is found in specification languages and functional programming languages. Algebraic data types can be emulated in Scala with case classes.

alternative A branch of a match expression. It has the form “case pattern => expression.” Another name for alternative is case.

annotation An annotation appears in source code and is attached to some part of the syntax. Annotations are computer processable, so you can use them to effectively add an extension to Scala.

anonymous class An anonymous class is a synthetic subclass generated by the Scala compiler from a new expression in which the class or trait name is followed by curly braces. The curly braces contains the body of the anonymous subclass, which may be empty. However, if the name following new refers to a trait or class that contains abstract members, these must be made concrete inside the curly braces that define the body of the anonymous subclass.

anonymous function Another name for function literal.

apply You can apply a method, function, or closure to arguments, which means you invoke it on those arguments.

argument When a function is invoked, an argument is passed for each parameter of that function. The parameter is the variable that refers to the argument. The argument is the object passed at invocation time. In addition, applications can take (command line) arguments that show up in the Array[String] passed to main methods of singleton objects.

assign You can assign an object to a variable. Afterwards, the variable will refer to the object.

auxiliary constructor Extra constructors defined inside the curly braces of the class definition, which look like method definitions named this, but with no result type.

block One or more expressions and declarations surrounded by curly braces. When the block evaluates, all of its expressions and declarations are processed in order, and then the block returns the value of the last expression as its own value. Blocks are commonly used as the bodies of functions, for expressions, while loops, and any other place where you want to group a number of statements together. More formally, a block is an encapsulation construct for which you can only see side effects and a result value. The curly braces in which you define a class or object do not, therefore, form a block, because fields and methods (which are defined inside those curly braces) are visible from the outside. Such curly braces form a template.

bound variable A bound variable of an expression is a variable that’s both used and defined inside the expression. For instance, in the function literal expression (x: Int) => (x, y), both variables x and y are used, but only x is bound, because it is defined in the expression as an Int and the sole argument to the function described by the expression.

by-name parameter A parameter that is marked with a => in front of the parameter type, e.g., (x: => Int). The argument corresponding to a by-name parameter is evaluated not before the method is invoked, but each time the parameter is referenced by name inside the method. If a parameter is not by-name, it is by-value.

by-value parameter A parameter that is not marked with a => in front of the parameter type, e.g., (x: Int). The argument corresponding to a by-value parameter is evaluated before the method is invoked. By-value parameters contrast with by-name parameters.

class Defined with the class keyword, a class may either be abstract or concrete, and may be parameterized with types and values when instantiated. In “new ArrayString“, the class being instantiated is Array and the type of the value that results is Array[String]. A class that takes type parameters is called a type constructor. A type can be said to have a class as well, as in: the class of type Array[String] is Array.

closure A function object that captures free variables, and is said to be “closed” over the variables visible at the time it is created.

companion class A class that shares the same name with a singleton object defined in the same source file. The class is the singleton object’s companion class.

companion object A singleton object that shares the same name with a class defined in the same source file. Companion objects and classes have access to each other’s private members. In addition, any implicit conversions defined in the companion object will be in scope anywhere the class is used.

contravariant A contravariant annotation can be applied to a type parameter of a class or trait by putting a minus sign (-) before the type parameter. The class or trait then subtypes contravariantly with—in the opposite direction as—the type annotated parameter. For example, Function1 is contravariant in its first type parameter, and so Function1[Any, Any] is a subtype of Function1[String, Any].

covariant A covariant annotation can be applied to a type parameter of a class or trait by putting a plus sign (+) before the type parameter. The class or trait then subtypes covariantly with—in the same direction as—the type annotated parameter. For example, List is covariant in its type parameter, so List[String] is a subtype of List[Any].

currying A way to write functions with multiple parameter lists. For instance def f(x: Int)(y: Int) is a curried function with two parameter lists. A curried function is applied by passing several arguments lists, as in: f(3)(4). However, it is also possible to write a partial application of a curried function, such as f(3).

declare You can declare an abstract field, method, or type, which gives an entity a name but not an implementation. The key difference between declarations and definitions is that definitions establish an implementation for the named entity, declarations do not.

define To define something in a Scala program is to give it a name and an implementation. You can define classes, traits, singleton objects, fields, methods, local functions, local variables, etc. Because definitions always involve some kind of implementation, abstract members are declared not defined.

direct subclass A class is a direct subclass of its direct superclass.

direct superclass The class from which a class or trait is immediately derived, the nearest class above it in its inheritance hierarchy. If a class Parent is mentioned in a class Child’s optional extends clause, then Parent is the direct superclass of Child. If a trait is mentioned in Child’s extends clause, the trait’s direct superclass is the Child’s direct superclass. If Child has no extends clause, then AnyRef is the direct superclass of Child. If a class’s direct superclass takes type parameters, for example class Child extends Parent[String], the direct superclass of Child is still Parent, not Parent[String]. On the other hand, Parent[String] would be the direct supertype of Child. See supertype for more discussion of the distinction between class and type.

equality When used without qualification, equality is the relation between values expressed by `==’. See also reference equality.

expression Any bit of Scala code that yields a result. You can also say that an expression evaluates to a result or results in a value.

filter An if followed by a boolean expression in a for expression. In for(i <- 1 to 10; if i % 2 == 0), the filter is “if i % 2 == 0”. The value to the right of the if is the filter expression.

filter expression A filter expression is the boolean expression following an if in a for expression. In for(i <- 1 to 10; if i % 2 == 0), the filter expression is “i % 2 == 0”.

first-class function Scala supports first-class functions, which means you can express functions in function literal syntax, i.e., (x: Int) => x + 1, and that functions can be represented by objects, which are called function values.

for comprehension Another name for for expression.

free variable A free variable of an expression is a variable that’s used inside the expression but not defined inside the expression. For instance, in the function literal expression (x: Int) => (x, y), both variables x and y are used, but only y is a free variable, because it is not defined inside the expression.

function A function can be invoked with a list of arguments to produce a result. A function has a parameter list, a body, and a result type. Functions that are members of a class, trait, or singleton object are called methods. Functions defined inside other functions are called local functions. Functions with the result type of Unit are called procedures. Anonymous functions in source code are called function literals. At run time, function literals are instantiated into objects called function values.

function literal A function with no name in Scala source code, specified with function literal syntax. For example, (x: Int, y: Int) => x + y.

function value A function object that can be invoked just like any other function. A function value’s class extends one of the FunctionN traits (e.g., Function0, Function1) from package scala, and is usually expressed in source code via function literal syntax. A function value is “invoked” when its apply method is called. A function value that captures free variables is a closure.

functional style The functional style of programming emphasizes functions and evaluation results and deemphasizes the order in which operations occur. The style is characterized by passing function values into looping methods, immutable data, methods with no side effects. It is the dominant paradigm of languages such as Haskell and Erlang, and contrasts with the imperative style.

generator A generator defines a named val and assigns to it a series of values in a for expression. For example, in for(i <- 1 to 10), the generator is “i <- 1 to 10”. The value to the right of the <- is the generator expression.

generator expression A generator expression generates a series of values in a for expression. For example, in for(i <- 1 to 10), the generator expression is “1 to 10”.

generic class A class that takes type parameters. For example, because scala.List takes a type parameter, scala.List is a generic class.

generic trait A trait that takes type parameters. For example, because trait scala.collection.Set takes a type parameter, it is a generic trait.

helper function A function whose purpose is to provide a service to one or more other functions nearby. Helper functions are often implemented as local functions.

helper method A helper function that’s a member of a class. Helper methods are often private.

immutable An object is immutable if its value cannot be changed after it is created in any way visible to clients. Objects may or may not be immutable.

imperative style The imperative style of programming emphasizes careful sequencing of operations so that their effects happen in the right order. The style is characterized by iteration with loops, mutating data in place, and methods with side effects. It is the dominant paradigm of languages such as C, C++, C# and Java, and contrasts with the functional style.

initialize When a variable is defined in Scala source code, you must initialize it with an object.

instance An instance, or class instance, is an object, a concept that exists only at run time.

instantiate To instantiate a class is to make a new object from the class, an action that happens only at run time.

invariant Invariant is used in two ways. It can mean a property that always holds true when a data structure is well-formed. For example, it is an invariant of a sorted binary tree that each node is ordered before its right subnode, if it has a right subnode. Invariant is also sometimes used as a synonym for nonvariant: “class Array is invariant in its type parameter.”

invoke You can invoke a method, function, or closure on arguments, meaning its body will be executed with the specified arguments.

JVM The JVM is the Java Virtual Machine, or runtime, that hosts a running Scala program.

literal 1, “One”, and (x: Int) => x + 1 are examples of literals. A literal is a shorthand way to describe an object, where the shorthand exactly mirrors the structure of the created object.

local function A local function is a def defined inside a block. To contrast, a def defined as a member of a class, trait, or singleton object is called a method.

local variable A local variable is a val or var defined inside a block. Although similar to local variables, parameters to functions are not referred to as local variables, but simply as parameters or “variables” without the “local.”

member A member is any named element of the template of a class, trait, or singleton object. A member may be accessed with the name of its owner, a dot, and its simple name. For example, top-level fields and methods defined in a class are members of that class. A trait defined inside a class is a member of its enclosing class. A type defined with the type keyword in a class is a member of that class. A class is a member of the package in which is it defined. By contrast, a local variable or local function is not a member of its surrounding block.

meta-programming Meta-programming software is software whose input is itself software. Compilers are meta-programs, as are tools like scaladoc. Meta-programming software is required in order to do anything with an annotation.

method A method is a function that is a member of some class, trait, or singleton object.

mixin Mixin is what a trait is called when it is being used in a mixin composition. In other words, in “trait Hat,” Hat is just a trait, but in “new Cat extends AnyRef with Hat,” Hat can be called a mixin. When used as a verb, “mix in” is two words. For example, you can mix traits into classes or other traits.

mixin composition The process of mixing traits into classes or other traits. Mixin composition differs from traditional multiple inheritance in that the type of the super reference is not known at the point the trait is defined, but rather is determined anew each time the trait is mixed into a class or other trait.

modifier A keyword that qualifies a class, trait, field, or method definition in some way. For example, the private modifier indicates that a class, trait, field, or method being defined is private.

multiple definitions The same expression can be assigned in multiple definitions if you use the syntax val v1, v2, v3 = exp.

nonvariant A type parameter of a class or trait is by default nonvariant. The class or trait then does not subtype when that parameter changes. For example, because class Array is nonvariant in its type parameter, Array[String] is neither a subtype nor a supertype of Array[Any].

operation In Scala, every operation is a method call. Methods may be invoked in operator notation, such as b + 2, and when in that notation, + is an operator.

parameter Functions may take zero to many parameters. Each parameter has a name and a type. The distinction between parameters and arguments is that arguments refer to the actual objects passed when a function is invoked. Parameters are the variables that refer to those passed arguments.

parameterless function A function that takes no parameters, which is defined without any empty parentheses. Invocations of parameterless functions may not supply parentheses. This supports the uniform access principle, which enables the def to be changed into a val without requiring a change to client code.

parameterless method A parameterless method is a parameterless function that is a member of a class, trait, or singleton object.

parametric field A field defined as a class parameter.

partially applied function A function that’s used in an expression and that misses some of its arguments. For instance, if function f has type Int => Int => Int, then f and f(1) are partially applied functions.

path-dependent type A type like swiss.cow.Food. The swiss.cow part is a path that forms a reference to an object. The meaning of the type is sensitive to the path you use to access it. The types swiss.cow.Food and fish.Food, for example, are different types.

pattern In a match expression alternative, a pattern follows each case keyword and precedes either a pattern guard or the => symbol.

pattern guard In a match expression alternative, a pattern guard can follow a pattern. For example, in “case x if x % 2 == 0 => x + 1”, the pattern guard is “if x % 2 == 0”. A case with a pattern guard will only be selected if the pattern matches and the pattern guard yields true.

predicate A predicate is a function with a Boolean result type.

primary constructor The main constructor of a class, which invokes a superclass constructor, if necessary, initializes fields to passed values, and executes any top-level code defined between the curly braces of the class. Fields are initialized only for value parameters not passed to the superclass constructor, except for any that are not used in the body of the class and can therefore be optimized away.

procedure A procedure is a function with result type of Unit, which is therefore executed solely for its side effects.

reassignable A variable may or may not be reassignable. A var is reassignable while a val is not.

receiver The receiver of a method call is the variable, expression, or object on which the method is invoked.

recursive A function is recursive if it calls itself. If the only place the function calls itself is the last expression of the function, then the function is tail recursive.

reference A reference is the Java abstraction of a pointer, which uniquely identifies an object that resides on the JVM’s heap. Reference type variables hold references to objects, because reference types (instances of AnyRef) are implemented as Java objects that reside on the JVM’s heap. Value type variables, by contrast, may sometimes hold a reference (to a boxed wrapper type) and sometimes not (when the object is being represented as a primitive value). Speaking generally, a Scala variable refers to an object. The term “refers” is more abstract than “holds a reference.” If a variable of type scala.Int is currently represented as a primitive Java int value, then that variable still refers to the Int object, but no reference is involved.

reference equality Reference equality means that two references identify the very same Java object. Reference equality can be determined, for reference types only, by calling eq in AnyRef. (In Java programs, reference equality can be determined using == on Java reference types.)

reference type A reference type is a subclass of AnyRef. Instances of reference types always reside on the JVM’s heap at run time.

referential transparency A property of functions that are independent of temporal context and have no side effects. For a particular input, an invocation of a referentially transparent function can be replaced by its result without changing the program semantics.

refers A variable in a running Scala program always refers to some object. Even if that variable is assigned to null, it conceptually refers to the Null object. At runtime, an object may be implemented by a Java object or a value of a primitive type, but Scala allows programmers to think at a higher level of abstraction about their code as they imagine it running. See also reference.

refinement type A type formed by supplying a base type a number of members inside curly braces. The members in the curly braces refine the types that are present in the base type. For example, the type of “animal that eats grass” is Animal { type SuitableFood = Grass }.

result An expression in a Scala program yields a result. The result of every expression in Scala is an object.

result type A method’s result type is the type of the value that results from calling the method. (In Java, this concept is called the return type.)

return A function in a Scala program returns a value. You can call this value the result of the function. You can also say the function results in the value. The result of every function in Scala is an object.

runtime The Java Virtual Machine, or JVM, that hosts a running Scala program. Runtime encompasses both the virtual machine, as defined by the Java Virtual Machine Specification, and the runtime libraries of the Java API and the standard Scala API. The phrase at run time (with a space between run and time) means when the program is running, and contrasts with compile time.

runtime type The type of an object at run time. To contrast, a static type is the type of an expression at compile time. Most runtime types are simply bare classes with no type parameters. For example, the runtime type of “Hi” is String, and the runtime type of (x: Int) => x + 1 is Function1. Runtime types can be tested with isInstanceOf.

script A file containing top level definitions and statements, which can be run directly with scala without explicitly compiling. A script must end in an expression, not a definition.

selector The value being matched on in a match expression. For example, in “s match { case _ => }”, the selector is s.

self type A self type of a trait is the assumed type of this, the receiver, to be used within the trait. Any concrete class that mixes in the trait must ensure that its type conforms to the trait’s self type. The most common use of self types is for dividing a large class into several traits as described in Chapter 32.

semi-structured data XML data is semi-structured. It is more structured than a flat binary file or text file, but it does not have the full structure of a programming language’s data structures.

serialization You can serialize an object into a byte stream which can then be saved to files or transmitted over the network. You can later deserialize the byte stream, even on different computer, and obtain an object that is the same as the original serialized object.

shadow A new declaration of a local variable shadows one of the same name in an enclosing scope.

signature Signature is short for type signature.

singleton object An object defined with the object keyword. Each singleton object has one and only one instance. A singleton object that shares its name with a class, and is defined in the same source file as that class, is that class’s companion object. The class is its companion class. A singleton object that doesn’t have a companion class is a standalone object.

standalone object A singleton object that has no companion class.

statement An expression, definition, or import, i.e., things that can go into a template or a block in Scala source code.

static type See type.

subclass A class is a subclass of all of its superclasses and supertraits.

subtrait A trait is a subtrait of all of its supertraits.

subtype The Scala compiler will allow any of a type’s subtypes to be used as a substitute wherever that type is required. For classes and traits that take no type parameters, the subtype relationship mirrors the subclass relationship. For example, if class Cat is a subclass of abstract class Animal, and neither takes type parameters, type Cat is a subtype of type Animal. Likewise, if trait Apple is a subtrait of trait Fruit, and neither takes type parameters, type Apple is a subtype of type Fruit. For classes and traits that take type parameters, however, variance comes into play. For example, because abstract class List is declared to be covariant in its lone type parameter (i.e., List is declared List[+A]), List[Cat] is a subtype of List[Animal], and List[Apple] a subtype of List[Fruit]. These subtype relationships exist even though the class of each of these types is List. By contrast, because Set is not declared to be covariant in its type parameter (i.e., Set is declared Set[A] with no plus sign), Set[Cat] is not a subtype of Set[Animal]. A subtype should correctly implement the contracts of its supertypes, so that the Liskov Substitution Principle applies, but the compiler only verifies this property at the level of type checking.

superclass A class’s superclasses include its direct superclass, its direct superclass’s direct superclass, and so on, all the way up to Any.

supertrait A class’s or trait’s supertraits, if any, include all traits directly mixed into the class or trait or any of its superclasses, plus any supertraits of those traits.

supertype A type is a supertype of all of its subtypes.

synthetic class A synthetic class is generated automatically by the compiler rather than being written by hand by the programmer.

tail recursive A function is tail recursive if the only place the function calls itself is the last operation of the function.

target typing Target typing is a form of type inference that takes into account the type that’s expected. In nums.filter((x) => x > 0), for example, the Scala compiler infers type of x to be the element type of nums, because the filter method invokes the function on each element of nums.

template A template is the body of a class, trait, or singleton object definition. It defines the type signature, behavior, and initial state of the class, trait, or object.

trait A trait, which is defined with the trait keyword, is like an abstract class that cannot take any value parameters and can be “mixed into” classes or other traits via the process known as mixin composition. When a trait is being mixed into a class or trait, it is called a mixin. A trait may be parameterized with one or more types. When parameterized with types, the trait constructs a type. For example, Set is a trait that takes a single type parameter, whereas Set[Int] is a type. Also, Set is said to be “the trait of” type Set[Int].

type Every variable and expression in a Scala program has a type that is known at compile time. A type restricts the possible values to which a variable can refer, or an expression can produce, at run time. A variable or expression’s type can also be referred to as a static type if necessary to differentiate it from an object’s runtime type. In other words, “type” by itself means static type. Type is distinct from class because a class that takes type parameters can construct many types. For example, List is a class, but not a type. List[T] is a type with a free type parameter. List[Int] and List[String] are also types (called ground types because they have no free type parameters). A type can have a “class” or “trait.” For example, the class of type List[Int] is List. The trait of type Set[String] is Set.

type constraint Some annotations are type constraints, meaning that they add additional limits, or constraints, on what values the type includes. For example, @positive could be a type constraint on the type Int, limiting the type of 32-bit integers down to those that are positive. Type constraints are not checked by the standard Scala compiler, but must instead be checked by an extra tool or by a compiler plugin.

type constructor A class or trait that takes type parameters.

type parameter A parameter to a generic class or generic method that must be filled in by a type. For example, class List is defined as “class List[T] { …”, and method identity, a member of object Predef, is defined as “def identityT = x”. The T in both cases is a type parameter.

type signature A method’s type signature comprises its name, the number, order, and types of its parameters, if any, and its result type. The type signature of a class, trait, or singleton object comprises its name, the type signatures of all of its members and constructors, and its declared inheritance and mixin relations.

uniform access principle The uniform access principle states that variables and parameterless functions should be accessed using the same syntax. Scala supports this principle by not allowing parentheses to be placed at call sites of parameterless functions. As a result, a parameterless function definition can be changed to a val, or vice versa, without affecting client code.

unreachable At the Scala level, objects can become unreachable, at which point the memory they occupy may be reclaimed by the runtime. Unreachable does not necessarily mean unreferenced. Reference types (instances of AnyRef) are implemented as objects that reside on the JVM’s heap. When an instance of a reference type becomes unreachable, it indeed becomes unreferenced, and is available for garbage collection. Value types (instances of AnyVal) are implemented as both primitive type values and as instances of Java wrapper types (such as java.lang.Integer), which reside on the heap. Value type instances can be boxed (converted from a primitive value to a wrapper object) and unboxed (converted from a wrapper object to a primitive value) throughout the lifetime of the variables that refer to them. If a value type instance currently represented as a wrapper object on the JVM’s heap becomes unreachable, it indeed becomes unreferenced, and is available for garbage collection. But if a value type currently represented as a primitive value becomes unreachable, then it does not become unreferenced, because it does not exist as an object on the JVM’s heap at that point in time. The runtime may reclaim memory occupied by unreachable objects, but if an Int, for example, is implemented at run time by a primitive Java int that occupies some memory in the stack frame of an executing method, then the memory for that object is “reclaimed” when the stack frame is popped as the method completes. Memory for reference types, such as Strings, may be reclaimed by the JVM’s garbage collector after they become unreachable.

unreferenced See unreachable.

value The result of any computation or expression in Scala is a value, and in Scala, every value is an object. The term value essentially means the image of an object in memory (on the JVM’s heap or stack).

value type A value type is any subclass of AnyVal, such as Int, Double, or Unit. This term has meaning at the level of Scala source code. At runtime, instances of value types that correspond to Java primitive types may be implemented in terms of primitive type values or instances of wrapper types, such as java.lang.Integer. Over the lifetime of a value type instance, the runtime may transform it back and forth between primitive and wrapper types (i.e., to box and unbox it).

variable A named entity that refers to an object. A variable is either a val or a var. Both vals and vars must be initialized when defined, but only vars can be later reassigned to refer to a different object.

variance A type parameter of a class or trait can be marked with a variance annotation, either covariant (+) or contravariant (-). Such variance annotations indicate how subtyping works for a generic class or trait. For example, the generic class List is covariant in its type parameter, and thus List[String] is a subtype of List[Any]. By default, i.e., absent a + or – annotation, type parameters are nonvariant.

wildcard type A wildcard type includes references to type variables that are unknown. For example, Array[_] is a wildcard type. It is an array where the element type is completely unknown.

yield An expression can yield a result. The yield keyword designates the result of a for expression.

Bibliography Scala Software Engineering

Programming Scala, 3rd Edition – B095XLMMGC – ISBN-13: 978-1492077893

See: Programming Scala, 3rd Edition, by Dean Wampler, Publisher ‏ : ‎ O’Reilly Media; 3rd edition (May 26, 2021)

Fair Use Source:

Get up to speed on Scala–the JVM, JavaScript, and natively compiled language that offers all the benefits of functional programming, a modern object model, and an advanced type system. Packed with code examples, this comprehensive book shows you how to be productive with the language and ecosystem right away. You’ll learn why Scala is ideal for building today’s highly scalable, data-centric applications while maximizing developer productivity.

While Java remains popular and Kotlin has become popular, Scala hasn’t been sitting still. This third edition covers the new features in Scala 3 with updates throughout the book. Programming Scala is ideal for beginning to advanced developers who want a complete understanding of Scala’s design philosophy and features with a thoroughly practical focus.

  • Program faster with Scala’s succinct and flexible syntax
  • Dive into basic and advanced functional programming techniques
  • Build killer big data and distributed apps using Scala’s functional combinators and tools like Spark and Akka
  • Create concise solutions to challenging design problems with the sophisticated type system, mixin composition with traits, pattern matching, and more


Errata Page:

Supplemental Content:

About the Author

Dean Wampler is an expert in data engineering for scalable streaming data systems and applications of machine learning and artificial intelligence. He is a principal software engineer at Domino Data Lab. Previously he worked at Anyscale and Lightbend, where he worked on scalable machine learning with Ray and distributed streaming data systems with Apache Spark, Apache Kafka, Kubernetes, and other tools. Besides Programming Scala, Dean is also the author of What Is Ray?, Distributed Computing Made Simple, Fast Data Architectures for Streaming Applications, and Functional Programming for Java Developers, as well as the coauthor of Programming Hive, all from O’Reilly. He is a contributor to several open source projects and a frequent conference speaker, and he co-organizes several conferences around the world and several user groups in Chicago. Dean has a PhD in physics from the University of Washington. Find Dean on Twitter: @deanwampler.

Table of Contents:

By Dean Wampler

  1. Foreword
  2. Foreword, Third Edition
  3. Foreword, First and Second Edition
  4. Preface
  5. Welcome to Programming Scala, Third Edition
  6. How to Read This Book
  7. Welcome to Programming Scala, Second Edition
  8. Welcome to Programming Scala, First Edition
  9. Conventions Used in This Book
  10. Using Code Examples
  11. Getting the Code Examples
  12. O’Reilly Online Learning
  13. How to Contact Us
  14. Acknowledgments for the Third Edition
  15. Acknowledgments for the Second Edition
  16. Acknowledgments for the First Edition
  17. 1. Zero To Sixty: Introducing Scalaqueue
  18. Why Scala?
  19. The Appeal of Scala
  20. Why Scala 3?
  21. Migrating to Scala 3
  22. Installing the Scala Tools You Need
  23. Building the Code Examples
  24. More Tips
  25. Using sbt
  26. Running the Scala Command-Line Tools Using sbt
  27. A Taste of Scala
  28. A Sample Application
  29. Recap and What’s Next
  30. 2. Type Less, Do Morequeue
  31. New Scala 3 Syntax—Optional Braces
  32. Semicolons
  33. Variable Declarations
  34. Ranges
  35. Partial Functions
  36. Method Declarations
  37. Method Default and Named Parameters
  38. Methods with Multiple Parameter Lists
  39. Nesting Method Definitions and Recursion
  40. Inferring Type Information
  41. Repeated Parameter Lists
  42. Language Keywords
  43. Literal Values
  44. Numeric Literals
  45. Boolean Literals
  46. Character Literals
  47. String Literals
  48. Symbol Literals
  49. Function Literals
  50. Tuples
  51. Option, Some, and None: Avoiding Nulls
  52. When You Really Can’t Avoid Nulls
  53. Sealed Class Hierarchies and Enumerations
  54. Organizing Code in Files and Namespaces
  55. Importing Types and Their Members
  56. Package Imports and Package Objects
  57. Parameterized Types Versus Abstract Type Members
  58. Recap and What’s Next
  59. 3. Rounding Out The Basics
  60. Defining Operators
  61. Allowed Characters in Identifiers
  62. Methods with Empty Parameter Lists
  63. Operator Precedence Rules
  64. Enumerations and Algebraic Data Types
  65. Interpolated Strings
  66. Scala Conditional Expressions
  67. Conditional and Comparison Operators
  68. for Comprehensions
  69. for Loops
  70. Generators
  71. Guards: Filtering Values
  72. Yielding New Values
  73. Expanded Scope and Value Definitions
  74. Scala while Loops
  75. Using try, catch, and finally Clauses
  76. Call by Name, Call by Value
  77. Lazy Values
  78. Traits: Interfaces and Mixins in Scala
  79. When new Is Optional
  80. Recap and What’s Next
  81. 4. Pattern Matching
  82. Safer Pattern Matching with Matchable
  83. Values, Variables, and Types in Matches
  84. Matching on Sequences
  85. Pattern Matching on Repeated Parameters
  86. Matching on Tuples
  87. Parameter Untupling
  88. Guards in Case Clauses
  89. Matching on Case Classes and Enums
  90. Matching on Regular Expressions
  91. Matching on Interpolated Strings
  92. Sealed Hierarchies and Exhaustive Matches
  93. Chaining Match Expressions
  94. Pattern Matching Outside Match Expressions
  95. Problems in Pattern Bindings
  96. Pattern Matching as Filtering in for Comprehensions
  97. Pattern Matching and Erasure
  98. Extractors
  99. unapply Method
  100. Alternatives to Option Return Values
  101. unapplySeq Method
  102. Implementing unapplySeq
  103. Recap and What’s Next
  104. 5. Abstracting Over Context: Type Classes And Extension Methodsqueue
  105. Four Changes
  106. Extension Methods
  107. Build Your Own String Interpolator
  108. Type Classes
  109. Scala 3 Type Classes
  110. Alias Givens
  111. Scala 2 Type Classes
  112. Scala 3 Implicit Conversions
  113. Type Class Derivation
  114. Givens and Imports
  115. Givens Scoping and Pattern Matching
  116. Resolution Rules for Givens and Extension Methods
  117. The Expression Problem
  118. Recap and What’s Next
  119. 6. Abstracting Over Context: Using Clauses
  120. Using Clauses
  121. Context Bounds
  122. Other Context Parameters
  123. Context Functions
  124. Constraining Allowed Instances
  125. Implicit Evidence
  126. Working Around Type Erasure with Using Clauses
  127. Rules for Using Clauses
  128. Improving Error Messages
  129. Recap and What’s Next
  130. 7. Functional Programming In Scalaqueue
  131. What Is Functional Programming?
  132. Functions in Mathematics
  133. Variables That Aren’t
  134. Functional Programming in Scala
  135. Anonymous Functions, Lambdas, and Closures
  136. Purity Inside Versus Outside
  137. Recursion
  138. Tail Calls and Tail-Call Optimization
  139. Partially Applied Functions Versus Partial Functions
  140. Currying and Uncurrying Functions
  141. Tupled and Untupled Functions
  142. Partial Functions Versus Functions Returning Options
  143. Functional Data Structures
  144. Sequences
  145. Maps
  146. Sets
  147. Traversing, Mapping, Filtering, Folding, and Reducing
  148. Traversing
  149. Mapping
  150. Flat Mapping
  151. Filtering
  152. Folding and Reducing
  153. Left Versus Right Folding
  154. Combinators: Software’s Best Component Abstractions
  155. What About Making Copies?
  156. Recap and What’s Next
  157. 8. For Comprehensions In Depthqueue
  158. Recap: The Elements of for Comprehensions
  159. for Comprehensions: Under the Hood
  160. Translation Rules of for Comprehensions
  161. Options and Container Types
  162. Option as a Container?
  163. Either: An Alternative to Option
  164. Try: When There Is No Do
  165. Validated from the Cats Library
  166. Recap and What’s Next
  167. 9. Object-Oriented Programming In Scalaqueue
  168. Class and Object Basics: Review
  169. Open Versus Closed Types
  170. Classes Open for Extension
  171. Overriding Methods? The Template Method Pattern
  172. Reference Versus Value Types
  173. Opaque Types and Value Classes
  174. Opaque Type Aliases
  175. Value Classes
  176. Supertypes
  177. Constructors in Scala
  178. Calling Supertype Constructors
  179. Export Clauses
  180. Good Object-Oriented Design: A Digression
  181. Fields in Types
  182. The Uniform Access Principle
  183. Unary Methods
  184. Recap and What’s Next
  185. 10. Traitsqueue
  186. Traits as Mixins
  187. Stackable Traits
  188. Union and Intersection Types
  189. Transparent Traits
  190. Using Commas Instead of with
  191. Trait Parameters
  192. Should That Type Be a Class or Trait?
  193. Recap and What’s Next
  194. 11. Variance Behavior And Equalityqueue
  195. Parameterized Types: Variance Under Inheritance
  196. Functions Under the Hood
  197. Variance of Mutable Types
  198. Improper Variance of Java Arrays
  199. Equality of Instances
  200. The equals Method
  201. The == and != Methods
  202. The eq and ne Methods
  203. Array Equality and the sameElements Method
  204. Equality and Inheritance
  205. Multiversal Equality
  206. Case Objects and hashCode
  207. Recap and What’s Next
  208. 12. Instance Initialization And Method Resolutionqueue
  209. Linearization of a Type Hierarchy
  210. Initializing Abstract Fields
  211. Overriding Concrete Fields
  212. Abstract Type Members and Concrete Type Aliases
  213. Recap and What’s Next
  214. 13. The Scala Type Hierarchyqueue
  215. Much Ado About Nothing (and Null)
  216. The scala Package
  217. Products, Case Classes, Tuples, and Functions
  218. Tuples and the Tuple Trait
  219. The Predef Object
  220. Implicit Conversions
  221. Type Definitions
  222. Condition Checking Methods
  223. Input and Output Methods
  224. Miscellaneous Methods
  225. Recap and What’s Next
  226. 14. The Scala Collections Libraryqueue
  227. Different Groups of Collections
  228. Abstractions with Multiple Implementations
  229. The scala.collection.immutable Package
  230. The scala.collection.mutable Package
  231. The scala.collection Package
  232. The scala.collection.concurrent Package
  233. The scala.collection.convert Package
  234. The scala.collection.generic Package
  235. Construction of Instances
  236. The Iterable Abstraction
  237. Polymorphic Methods
  238. Equality for Collections
  239. Nonstrict Collections: Views
  240. Recap and What’s Next
  241. 15. Visibility Rulesqueue
  242. Public Visibility: The Default
  243. Visibility Keywords
  244. Protected Visibility
  245. Private Visibility
  246. Scoped Private and Protected Visibility
  247. Recap and What’s Next
  248. 16. Scala’s Type System, Part Iqueue
  249. Parameterized Types
  250. Abstract Type Members and Concrete Type Aliases
  251. Comparing Abstract Type Members Versus Parameterized Types
  252. Type Bounds
  253. Upper Type Bounds
  254. Lower Type Bounds
  255. Context Bounds
  256. View Bounds
  257. Intersection and Union Types
  258. Intersection Types
  259. Union Types
  260. Phantom Types
  261. Structural Types
  262. Refined Types
  263. Existential Types (Obsolete)
  264. Recap and What’s Next
  265. 17. Scala’s Type System, Part IIqueue
  266. Match Types
  267. Dependently Typed Methods
  268. Dependent Method and Dependent Function Types
  269. Dependent Typing
  270. Path-Dependent Types
  271. Using this
  272. Using super
  273. Stable Paths
  274. Self-Type Declarations
  275. Type Projections
  276. More on Singleton Types
  277. Self-Recursive Types: F-Bounded Polymorphism
  278. Higher-Kinded Types
  279. Type Lambdas
  280. Polymorphic Functions
  281. Type Wildcard Versus Placeholder
  282. Recap and What’s Next
  283. 18. Advanced Functional Programmingqueue
  284. Algebraic Data Types
  285. Sum Types Versus Product Types
  286. Properties of Algebraic Data Types
  287. Final Thoughts on Algebraic Data Types
  288. Category Theory
  289. What Is a Category?
  290. Functor
  291. The Monad Endofunctor
  292. The Semigroup and Monoid Categories
  293. Recap and What’s Next
  294. 19. Tools For Concurrencyqueue
  295. The scala.sys.process Package
  296. Futures
  297. Robust, Scalable Concurrency with Actors
  298. Akka: Actors for Scala
  299. Actors: Final Thoughts
  300. Stream Processing
  301. Recap and What’s Next
  302. 20. Dynamic Invocation In Scalaqueue
  303. Structural Types Revisited
  304. A Motivating Example: ActiveRecord in Ruby on Rails
  305. Dynamic Invocation with the Dynamic Trait
  306. DSL Considerations
  307. Recap and What’s Next
  308. 21. Domain-Specific Languages In Scalaqueue
  309. Internal DSLs
  310. External DSLs with Parser Combinators
  311. About Parser Combinators
  312. A Payroll External DSL
  313. Internal Versus External DSLs: Final Thoughts
  314. Recap and What’s Next
  315. 22. Scala Tools And Librariesqueue
  316. Scala 3 Versions
  317. Command-Line Interface Tools
  318. Coursier
  319. Managing Java JDKs with Coursier
  320. The scalac Command-Line Tool
  321. The scala Command-Line Tool
  322. The scaladoc Command-Line Tool
  323. Other Scala Command-Line Tools
  324. Build Tools
  325. Integration with IDEs and Text Editors
  326. Using Notebook Environments with Scala
  327. Testing Tools
  328. Scala for Big Data: Apache Spark
  329. Typelevel Libraries
  330. Li Haoyi Libraries
  331. Java and Scala Interoperability
  332. Using Java Identifiers in Scala Code
  333. Scala Identifiers in Java Code
  334. Java Generics and Scala Parameterized Types
  335. Conversions Between Scala and Java Collections
  336. Java Lambdas Versus Scala Functions
  337. Annotations for JavaBean Properties and Other Purposes
  338. Recap and What’s Next
  339. 23. Application Designqueue
  340. Recap of What We Already Know
  341. Annotations
  342. Using @main Entry Points
  343. Design Patterns
  344. Creational Patterns
  345. Structural Patterns
  346. Behavioral Patterns
  347. Better Design with Design by Contract
  348. The Parthenon Architecture
  349. Recap and What’s Next
  350. 24. Metaprogramming: Macros And Reflectionqueue
  351. Scala Compile Time Reflection
  352. Java Runtime Reflection
  353. Scala Reflect API
  354. Type Class Derivation: Implementation Details
  355. Scala 3 Metaprogramming
  356. Inline
  357. Macros
  358. Staging
  359. Wrapping Up and Looking Ahead
  360. A. Significant Indentation Versus Braces Syntaxqueue
  361. Bibliography
Bibliography Scala Software Engineering

Scala Cookbook: Recipes for Object-Oriented and Functional Programming, 2nd Edition – ISBN-13: 978-1492051541, 2021

See: Scala Cookbook: Recipes for Object-Oriented and Functional Programming, 2nd Edition, Publisher ‏ : ‎ O’Reilly Media; 2nd edition (August 31, 2021)

Fair Use Source:

Save time and trouble building object-oriented, functional, and concurrent applications with Scala 3. The latest edition of this comprehensive cookbook is packed with more than 250 ready-to-use recipes and 700 code examples to help you solve the most common problems when working with Scala and its popular libraries.

Whether you’re working on web, big data, or distributed applications, this cookbook provides recipes based on real-world scenarios for experienced Scala developers and for programmers just learning to use this JVM language. Author Alvin Alexander includes practical solutions from his experience using Scala for highly scalable applications that support concurrency and distribution.

Recipes cover:

  • Strings, numbers, and control structures
  • Classes, methods, objects, traits, packaging, and imports
  • Functional programming in a variety of situations
  • Building Scala applications with sbt
  • Collections covering Scala’s wealth of classes and methods
  • Actors and concurrency
  • List, array, map, set, and more
  • Files, processes, and command-line tasks
  • Web services and interacting with Java
  • Databases and persistence, data types and idioms


Errata Page:

Bibliography Scala Software Engineering

Functional Programming, Simplified: Scala Edition – B076J7CJKY ISBN-13: 978-1979788786, 2017

See: Functional Programming, Simplified: Scala Edition, by Alvin Alexander, Publisher ‏ : ‎ CreateSpace Independent Publishing Platform (December 7, 2017)

Fair Use Source:

If you’ve had trouble trying to learn Functional Programming (FP), you’re not alone. In this book, Alvin Alexander — author of the Scala Cookbook and former teacher of Java and Object-Oriented Programming (OOP) classes — writes about his own problems in trying to understand FP, and how he finally conquered it.

What he originally learned is that experienced FP developers are driven by two goals: to use only immutable values, and write only pure functions. What he later learned is that they have these goals as the result of another larger goal: they want all of their code to look and work just like algebra.

While that sounds simple, it turns out that these goals require them to use many advanced Scala features — which they often use all at the same time. As a result, their code can look completely foreign to novice FP developers. As Mr. Alexander writes, “When you first see their code it’s easy to ask, ‘Why would anyone write code like this?’”

Mr. Alexander answers that “Why?” question by explaining the benefits of writing pure functional code. Once you understand those benefits — your motivation for learning FP — he shares five rules for programming in the book:

  • All fields must be immutable (‘val’ fields).
  • All functions must be pure functions.
  • Null values are not allowed.
  • Whenever you use an ‘if’ you must also use an ‘else’.
  • You won’t create OOP classes that encapsulate data and behavior; instead you’ll design data structures using Scala ‘case’ classes, and write pure functions that operate on those data structures.

In the book you’ll see how those five, simple rules naturally lead you to write pure, functional code that reads like algebra. He also shares one more Golden Rule for learning:

  • Always ask “Why”?

Lessons in the book include:

  • How and why to write only pure functions
  • Why pure function signatures are much more important than OOP method signatures
  • Why recursion is a natural tool for functional programming, and how to write recursive algorithms
  • Because the Scala ‘for’ expression is so important to FP, dozens of pages explain the details of how it works
  • In the end you’ll see that monads aren’t that difficult because they’re a natural extension of the Five Rules
  • The book finishes with lessons on FP data modeling, and two main approaches for organizing your pure functions

As Mr. Alexander writes, “In this book I take the time to explain all of the concepts that are used to write FP code in Scala. As I learned from my own experience, once you understand the Five Rules and the small concepts, you can understand Scala/FP.”

Please note that because of the limits on how large a printed book can be, the paperback version does not include all of the chapters that are in the Kindle eBook. The following lessons are not in the paperback version:

  • Grandma’s Cookies (a story about pure functions)
  • The ScalaCheck lessons
  • The Type Classes lessons
  • The appendices

Because those lessons didn’ fit in the print version, they have been made freely available online.

(Alvin Alexander ( wrote the popular Scala Cookbook for O’Reilly, and also self-published two other books, How I Sold My Business: A Personal Diary, and A Survival Guide for New Consultants.)

About the Author

Alvin took the circuitous route to software development. He managed to get a degree in Aerospace Engineering from Texas A&M University, while all he was really trying to do was play baseball. Once he became a practicing engineer, he realized he liked software and programming more than engineering. So in approximate order he taught himself Fortran, C, Unix, network administration, sed, awk, Lisp, Perl, Java, JavaScript, Python, Ruby, JRuby, PHP, and Scala. During this process he started a software consulting firm, grew it to fifteen people, sold it, and moved to Alaska. After returning to the “Lower 48,” he self-published two books (“How I Sold My Business: A Personal Diary”, and “Zen and the Art of Consulting”), and then wrote the “Scala Cookbook” for O’Reilly. He also created, which receives millions of page views every year.

Bibliography Kotlin Scala Software Engineering

Hello, Scala – B079WK8P1X ISBN-13: 978-1720790020, 2018

See: Hello, Scala: Learn Scala fast with small, easy lessons, by Alvin Alexander, Publisher ‏ : ‎ CreateSpace Independent Publishing Platform (September 8, 2018)

Fair Use Source:

Update: In July, 2021, the price of this Kindle book has been drastically reduced so you can learn Scala as inexpensively as possible.

In his latest book, Alvin Alexander, author of the Scala Cookbook and Functional Programming, Simplified, brings you a swift introduction to the Scala programming language. In a little over 200 fast-paced pages, Mr. Alexander demonstrates that Scala is a beautiful, modern, expressive programming language. The book is broken down into 56 short chapters to help you easily find what you need. Lessons include:

  • An introduction to Scala’s two types of variables, `val` and `var`
  • Scala control structures, including powerful `for` expressions and `match` expressions
  • An overview of Scala collections classes and methods
  • Object-oriented programming (OOP), including features of Scala classes and methods
  • Functional programming (FP), including pure functions, using functions as variables, case classes, match expressions, functional error handling, and more
  • Modular programming with traits
  • How to build Scala projects with SBT
  • How to write TDD and BDD unit tests with ScalaTest
  • Programming concurrency with Akka actors and Scala futures

To help get you started with Scala as fast as possible, the book shares many source code examples, including several open source Github projects that you can run immediately. All examples in the book have been written with Scala 2.12, and represent 2018’s “best practices” for Scala programming.

About the Author

Alvin took the circuitous route to software development. He managed to get a degree in Aerospace Engineering from Texas A&M University, while all he was really trying to do was play baseball. Once he became a practicing engineer, he realized he liked software and programming more than engineering. So in approximate order he taught himself Fortran, C, Unix, network administration, sed, awk, Lisp, Perl, Java, JavaScript, Python, Ruby, JRuby, PHP, and Scala. During this process he started a software consulting firm, grew it to fifteen people, sold it, and moved to Alaska. After returning to the “Lower 48,” he self-published two books (“How I Sold My Business: A Personal Diary”, and “Zen and the Art of Consulting”), and then wrote the “Scala Cookbook” for O’Reilly. He also created, which receives millions of page views every year.

Table of Contents:

Table of Contents



Prelude: A Taste of Scala

Getting started

The Scala Programming Language

Hello, World

Hello, World (Version 2)

The Scala REPL

Two Types of Variables

The Type is Optional

A Few Built-In Types

Two Notes About Strings

Command-Line I/O

Control Structures

The if/then/else Construct

for Loops

for Expressions

match Expressions

try/catch/finally Expressions


Auxiliary Class Constructors

Supplying Default Values for Constructor Parameters

A First Look at Methods

Enumerations (and a Complete Pizza Class)

Traits and Abstract Classes

Using Traits as Interfaces

Using Traits Like Abstract Classes

Abstract Classes

Collections Classes

ArrayBuffer Class

List Class

Vector Class

Map Class

Set Class

Anonymous Functions

Common Methods on Sequences

Common Map Methods

A Few Miscellaneous Items


Scala and Swing

An OOP Example

A Scala + JavaFX Example

SBT and ScalaTest

The Scala Build Tool (SBT)

Using ScalaTest with SBT

Writing BDD-style tests with ScalaTest and SBT

Functional Programming

Pure Functions

Passing Functions Around

No Null Values

Companion Objects

Case Classes

Case Objects

Functional Error Handling


Akka Actors

Akka Actor Examples




  1. Preface

Have you ever fallen in love with a programming language? I still remember when I first saw the book, The C Programming Language, and how I fell in love with its simple syntax and the ability to interact with a computer at a low level. In 1996 I loved Java because it made OOP simple. A few years later I found Ruby and loved its elegance.

Then in 2011 I was aimlessly wandering around Alaska and stumbled across the book, Programming in Scala, and I was stunned by its remarkable marriage of Ruby and Java:

The syntax was as elegant and concise as Ruby

It feels dynamic, but it’s statically typed

It compiles to class files that run on the JVM

You can use the thousands of Java libraries in existence with your Scala code

In the first edition of the book, Beginning Scala, David Pollak states that Scala will change the way you think about programming, and that’s a good thing. Learning Scala has not only been a joy, but it’s led me on a journey to appreciate concepts like modular programming, immutability, referential transparency, and functional programming, and most importantly, how those ideas help to dramatically reduce bugs in my code.

Is Scala DICEE?

DICEE is an acronym that was coined by Guy Kawasaki, who became famous as a developer evangelist for the original Apple Macintosh team. He says that great products are DICEE, meaning Deep, Indulgent, Complete, Elegant, and Emotive:

Deep: The product doesn’t run out of features and functionality after a few weeks of use. Its creators have anticipated what you’ll need once you come up to speed. As your demands get more sophisticated, you won’t need a different product.

Indulgent: A great product is a luxury. It makes you feel special when you buy it (and use it).

Complete: A great product is more than a physical thing. Documentation counts. Customer service counts. Tech support counts.

Elegant: A great product has an elegant user interface. Things work the way you’d think they would. A great product doesn’t fight you, it enhances you.

Emotive: A great product incites you to action. It is so deep, indulgent, complete, and elegant that it compels you to tell other people about it. You’re bringing the good news to help others, not yourself.

Two years after discovering Scala — way back in 2013 — I came to the conclusion that it meets the definition of DICEE, and I think it’s just as true today:

Scala is deep: After all these years I continue to learn new techniques to write better code.

Scala is indulgent: Just like Ruby, I feel special and fortunate to use a language that’s so well thought out.

Scala is complete: The documentation is excellent, terrific frameworks exist, and the support groups are terrific.

Scala is elegant: Once you grasp its main concepts you’ll fall in love with how it works just like you expect it to.

Scala is emotive: Everyone who works with it wants to tell you how special it is. Myself, I had never written a programming book in my life, but by 2012 I was eagerly mailing people at O’Reilly to tell them how much I wanted to write the Scala Cookbook.

As I write this book many years later I hope to share not just the nuts and bolts of the Scala language, but also its elegance and the joy of using it.

Alvin Alexander

Bibliography Java Kotlin Software Engineering

Modern Java Recipes: Simple Solutions to Difficult Problems in Java 8 and 9, 1st Edition – B074R6B13N ISBN-13: 978-1491973172

See: Modern Java Recipes: Simple Solutions to Difficult Problems in Java 8 and 9, 1st Edition, Publisher ‏ : ‎ O’Reilly Media; 1st edition (August 11, 2017)

Fair Use Source:

The introduction of functional programming concepts in Java SE 8 was a drastic change for this venerable object-oriented language. Lambda expressions, method references, and streams fundamentally changed the idioms of the language, and many developers have been trying to catch up ever since. This cookbook will help. With more than 70 detailed recipes, author Ken Kousen shows you how to use the newest features of Java to solve a wide range of problems.

For developers comfortable with previous Java versions, this guide covers nearly all of Java SE 8, and includes a chapter focused on changes coming in Java 9. Need to understand how functional idioms will change the way you write code? This cookbook—chock full of use cases—is for you.

Recipes cover:

  • The basics of lambda expressions and method references
  • Interfaces in the java.util.function package
  • Stream operations for transforming and filtering data
  • Comparators and Collectors for sorting and converting streaming data
  • Combining lambdas, method references, and streams
  • Creating instances and extract values from Java’s Optional type
  • New I/O capabilities that support functional streams
  • The Date-Time API that replaces the legacy Date and Calendar classes
  • Mechanisms for experimenting with concurrency and parallelism

About the Author

Ken Kousen is an independent consultant and trainer specializing in Spring, Hibernate, Groovy, and Grails. He holds numerous technical certifications, along with degrees in Mathematics, Mechanical and Aerospace Engineering, and Computer Science.


Errata Page:

Bibliography Kotlin Software Engineering

Java to Kotlin: A Refactoring Guidebook, 1st Edition – ISBN-13: 978-1492082279

See: Java to Kotlin: A Refactoring Guidebook, 1st Edition, Publisher ‏ : ‎ O’Reilly Media; 1st edition (September 14, 2021)

Fair Use Source:

See also: Kotlin

Kotlin has raised the bar for programming languages on the Java Virtual Machine with its compatibility, readability, efficiency, and tool support. But adopting a new language can be daunting, especially when you’re working with business-critical Java code that must meet changing requirements.

This book takes a novel approach to introducing Kotlin to Java programmers: showing you how to gradually refactor Java code to idiomatic Kotlin while continuing to evolve its functionality. But converting Java to Kotlin is just the starting point. Kotlin has many features beyond Java.

Using worked examples, authors Duncan McGregor and Nat Pryce guide you through honing the converted code to make it simpler, more efficient, more expressive, and easier to change. You’ll learn how to take advantage of functional constructs to improve program structure, reliability, and error handling.

Once you finish this book, you’ll be confident writing Kotlin from scratch, converting your existing Java when appropriate, and managing a mixed Java-Kotlin codebase as it evolves over time.


Errata Page:

Bibliography Kotlin Software Engineering

Programming Kotlin: Create Elegant, Expressive, and Performant JVM and Android Applications, 1st Edition – B084P613XT ISBN-13: 978-1680506358

See: Programming Kotlin: Create Elegant, Expressive, and Performant JVM and Android Applications, 1st Edition, Publisher ‏ : ‎ Pragmatic Bookshelf; 1st edition (October 1, 2019)

Fair Use Source:

See also: Kotlin

Programmers don’t just use Kotlin, they love it. Even Google has adopted it as a first-class language for Android development. With Kotlin, you can intermix imperative, functional, and object-oriented styles of programming and benefit from the approach that’s most suitable for the problem at hand. Learn to use the many features of this highly concise, fluent, elegant, and expressive statically typed language with easy-to-understand examples. Learn to write easy-to-maintain, high-performing JVM and Android applications, create DSLs, program asynchrony, and much more.

Kotlin is a highly concise, elegant, fluent, and expressive statically typed multi-paradigm language. It is one of the few languages that compiles down to both Java bytecode and JavaScript. You can use it to build server-side, front-end, and Android applications. With Kotlin, you need less code to accomplish your tasks, while keeping the code type-safe and less prone to error. If you want to learn the essentials of Kotlin, from the fundamentals to more advanced concepts, you’ve picked the right book.

Fire up your favorite IDE and practice hundreds of examples and exercises to sharpen your Kotlin skills. Learn to build standalone small programs to run as scripts, create type safe code, and then carry that knowledge forward to create fully object-oriented and functional style code that’s easier to extend. Learn how to program with elegance but without compromising efficiency or performance, and how to use metaprogramming to build highly expressive code and create internal DSLs that exploit the fluency of the language. Explore coroutines, program asynchrony, run automated tests, and intermix Kotlin with Java in your enterprise applications.

This book will help you master one of the few languages that you can use for the entire full stack – from the server to mobile devices – to create performant, concise, and easy to maintain applications.

What You Need:

To try out the examples in the book you’ll need a computer with Kotlin SDK, JDK, and a text editor or a Kotlin IDE installed in it.


Errata Page:

Bibliography Kotlin Software Engineering

Kotlin – Guide pratique – Des réponses concrètes aux cas d’utilisation (French Edition) – B08BFPJXSS ISBN-13: 978-2412053287

See: Kotlin les fondamentaux – Une approche concrète pour tous les cas pratiques – collection O’Reilly – (French Edition), Publisher ‏ : ‎ FIRST INTERACT (June 18, 2020)

Fair Use Source:

See also: Kotlin Cookbook: A Problem-Focused Approach, 1st Edition – B081HYY9BS ISBN-13: 978-1492046677 and Kotlin

Kotlin, le nouveau langage qui monte qui monte

Kotlin permet de développer des applications Android, des applications Web, et bien plus encore. Grâce à ce livre unique, les développeurs apprendront comment utiliser ce langage de type Java dans tous leurs développements.

L’auteur se consacre à des études de cas plus que sur la syntaxe pure du langage. Bien que très utilisé dans le développement Android, Kotlin peut se substituer à Java dans bien d’autres développement, par exemple celui d’applications iOS.

Au programme :

Les concepts de la programmation fonctionnelle
L’interopérabilité de Java et l’accès à ses bibliothèques avec Kotlin
Ajoutez vos propres fonctions
Utiliser le framework JUnit 5
Travailler avec des frameworks spécifiques comme Android et Spring

About the Author

Ken Kousen es un gourou du langage Java et ambassadeur pour Oracle. Il a écrit de nombreux livres pour O’Reilly sur des sujets comme Android, Java et bien d’autres encore. Il a participé à de nombreux développements d’applications. Il est certifié développeur Kotlin
Il est également fondateur et président de la société Kousen IT, Inc. une société spécialisée dans le consulting et la formation Android, Spring, Hibernate/JPA, Groovy, et Grails.

Bibliography Kotlin Software Engineering

Kotlin Cookbook: A Problem-Focused Approach, 1st Edition – B081HYY9BS ISBN-13: 978-1492046677

See: Kotlin Cookbook: A Problem-Focused Approach, 1st Edition, Publisher ‏ : ‎ O’Reilly Media; 1st edition (November 14, 2019)

Fair Use Source:

See also: Kotlin – Guide pratique – Des réponses concrètes aux cas d’utilisation (French Edition) – B08BFPJXSS ISBN-13: 978-2412053287 and Kotlin

Use Kotlin to build Android apps, web applications, and more—while you learn the nuances of this popular language. With this unique cookbook, developers will learn how to apply thisJava-based language to their own projects. Both experienced programmers and those new to Kotlin will benefit from the practical recipes in this book.

Author Ken Kousen (Modern Java Recipes) shows you how to solve problems with Kotlin by concentrating on your own use cases rather than on basic syntax. You provide the contextand this book supplies the answers. Already big in Android development, Kotlin can be used anywhere Java is applied, as well as for iOS development, native applications, JavaScriptgeneration, and more. Jump in and build meaningful projects with Kotlin today.

  • Apply functional programming concepts, including lambdas, sequences, and concurrency
  • See how to use delegates, late initialization, and scope functions
  • Explore Java interoperability and access Java libraries using Kotlin
  • Add your own extension functions
  • Use helpful libraries such as JUnit 5
  • Get practical advice for working with specific frameworks, like Android and Spring


Errata Page: Content:

Bibliography Kotlin Software Engineering

Kotlin Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides), 1st Edition – B07FXQ7SQN ISBN-13: 978-0135161630

See: Kotlin Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides), 1st Edition, Publisher ‏ : ‎ Big Nerd Ranch; 1st edition (July 13, 2018)

Fair Use Source:

See also: Kotlin

Kotlin is a statically typed programming language designed to interoperate with Java and fully supported by Google on the Android operating system.

Based on Big Nerd Ranch’s popular Kotlin Essentials course, this guide shows you how to work effectively with the Kotlin programming language through hands-on examples and clear explanations of key Kotlin concepts and foundational APIs. Written for Kotlin 1.2, this book will also introduce you to JetBrains’ IntelliJ IDEA development environment.

Whether you are an experienced Android developer looking for modern features beyond what Java offers or a new developer ready to learn your first programming language, the authors will guide you from first principles to advanced usage of Kotlin. By the end of this book, you will be empowered to create reliable, concise applications in Kotlin.

Bibliography Kotlin Software Engineering

Atomic Kotlin – ISBN-13: 978-0981872551

See: Atomic Kotlin, Publisher ‏ : ‎ Mindview LLC (January 11, 2021)

Fair Use Source:

See also: Kotlin

For both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest “atoms,” along with exercises supported by hints and solutions directly inside IntelliJ IDEA!

  • No programming background necessary.
  • Summaries for experienced programmers.
  • Easy steps via very small chapters (“atoms”).
  • Free accompanying exercises/solutions within IntelliJ Idea.
  • Gives you a strong Kotlin foundation.
  • Kotlin is cleaner, more consistent and far more powerful than Java.
  • Increase programming productivity with Kotlin’s clear, concise syntax.
  • Produce safer, more reliable programs.
  • Kotlin easily interacts with Java.
  • Effortlessly migrate by adding pieces of Kotlin to an existing Java project.
  • Support for Windows, Mac and Linux.
  • Free version of Intellij IDEA includes extensive Kotlin support.
  • Book resources, live seminars, workshops and consulting available at