Leanpub Header

Skip to main content

Topics

Scala

From the language and its type system to Cats, ZIO, Play, Akka HTTP, event sourcing and Spark, Scala as told through the free samples of Leanpub books.

Created from the free samples of 10 Leanpub books and the descriptions and tables of contents of 11 more, with every source cited.

Scala is a statically typed programming language that joins object-oriented and functional programming in one design. Every value is an object and every function is a value, so a program can be written with immutable data and functions free of side effects, with classes, inheritance and mutable state, or, as is usual, with a mixture of the two.[1] It compiles to Java bytecode and runs on the Java virtual machine, which gives it the whole body of Java libraries.[3]

The language was designed in a university research laboratory in Switzerland and first released to the public in 2004; its name joins "scalable" and "language".[1] It has kept a small and steady share of professional use, and two widely used pieces of data infrastructure, Apache Spark and Apache Kafka, are written in it.[1] Its community is unusually varied for its size. One author observes that the same language holds frameworks a newcomer can learn in a couple of weeks and libraries built on abstractions from category theory.[2]

This article covers the language's history and versions, its two paradigms and its type system, the functional libraries, web development, architecture patterns worked out in Scala, data processing and artificial intelligence, and tooling. Its sources are the free samples of ten Leanpub books and the descriptions and tables of contents of eleven more, published between 2016 and 2026. More than half of the books date from 2022 or earlier and teach Scala 2; the article gives each book's year, and its section on versions explains what changed.

Where to start

A programmer who knows another language has several first books. Scala from Scratch: Exploration (2020) is the first of two volumes for readers with experience of an object-oriented or imperative language, and ends with a small command-line application; Scala from Scratch: Understanding (2020) continues from it into the type system and the idioms of working projects.[14][15] Scala For Beginners (2019) is arranged as seven days of material and is addressed to complete beginners and to data engineers who need Scala for other tools.[8] Scala Masterclass: From Fundamentals to Advanced Patterns (2026) is the only introduction in the pool written in Scala 3 syntax, with notes for readers coming from Scala 2.[1]

A web developer can learn the language through a framework. Modern Web Development with Scala (2020) expects no Scala and teaches enough of it to build an application with Play.[3] Its author's next book, Mastering Advanced Scala (2020), is for people who already write Scala applications.[2]

The functional programming books assume more. Functional Programming for Mortals (2026) describes its reader as a Scala developer, probably from Java, who is sceptical of and curious about the functional style, and says plainly that it is not for beginners.[11] Practical FP in Scala (2021) is for developers who know the basics of functional effects and want to see a whole application.[4] Effect Oriented Programming (2024) aims to make effect systems accessible to all developers.[12]

History and versions

Work on the language began in 2001 with a question: could one language bridge object-oriented and functional programming without making the programmer choose? Its designer had worked on generics for Java and on the Java compiler, and the first public release, in January 2004, targeted the Java platform.[1] The design drew on Java and C# for its object model, on the ML family and Haskell for functional constructs and types, and on Erlang for ideas about concurrency.[1]

Version 2.0, in 2006, rewrote the compiler in Scala and introduced implicits, match expressions and for-comprehensions. The 2.x series then ran for more than a decade: 2.8 in 2010 unified the collections, 2.10 in 2013 added futures and string interpolation, 2.12 required Java 8, and 2.13 in 2019 redesigned the collections library.[1] Industry adoption came in the same years. One author dates it from the middle of 2008, when a large social network rewrote part of its core in Scala and several other well-known sites followed, and writes that the language had been ready for production work at least since 2011.[3]

Scala 3, released in May 2021 after years of development, is the largest change since 2.0: a redesign meant to reduce accumulated complexity and not an incremental update.[1] A long-term support line began with 3.3 in 2023, and as of the middle of 2026 the latest release is 3.8, which requires Java 17.[1] The books divide along this line. Those from 2019 to 2021 use Scala 2.12 or 2.13 and its implicit syntax; Pure functional HTTP APIs in Scala (2022) added a chapter on moving its project to Scala 3 in its second edition; and the books of 2026 are written for Scala 3.[6][13][16]

Where Scala is used

The masterclass describes the language's standing as steady and modest. Language rankings have placed it between twelfth and sixteenth for most of a decade, and in a large developer survey of 2024 under three per cent of respondents had worked extensively in it during the previous year, while reporting pay above that of most other languages.[1] The book argues that its influence is wider than its use: features it made familiar, algebraic data types and functional operations on collections among them, have since appeared in several newer and several older languages.[1]

It names three fields of use. The first is web services with heavy traffic, where strong typing and support for concurrency count, served by frameworks from Play to http4s. The second is data processing, since teams that build pipelines on Spark often write Scala to get the most from it. The third is financial services, where trading and asset-management systems are held to a high standard of correctness.[1] An author writing in 2020 complained that much of the public still took Scala for a niche language a decade after companies had put it into production, and gave as its advantage over Java that high-level constructs come without a cost in speed.[3] A book of 2025 records the other side: its author considered moving to a newer language on the same virtual machine and to another framework, and stayed with Scala and Play by preference.[7]

One language, two paradigms

The mixture of styles is deliberate. The masterclass gives the example of a web service whose domain model is immutable and whose business logic is pure, while its event loop uses mutable buffers for speed, both in one language.[1] The usual blend uses case classes to model data, traits to share behaviour, higher-order functions to transform collections and pattern matching for control flow.[1] The standard library supplies types such as Option, Try and Future, which stand for a value that may be absent, a computation that may fail and a result that will arrive later.[2] Scala from Scratch: Exploration gives Option a full chapter as the language's answer to null references, and teaches the design of data types that enforce their own rules without throwing exceptions.[14]

The preface of Practical FP in Scala describes the path many Scala programmers take. The hybrid design lets a newcomer be productive without knowing the language in detail; with time the functional building blocks, pattern matching, folds, recursion and higher-order functions, come to seem its strength, and from there the programmer finds the functional part of the community and its libraries.[4]

Implicits and type classes

The feature that most marks Scala 2 code is the implicit. A function parameter declared implicit need not be passed by the caller when a suitable value marked implicit is in scope, and the compiler also looks in the companion objects of the types involved.[2] Implicit conversions let a programmer add methods to classes from other libraries, a job done in dynamic languages by patching the class at run time.[2]

On these the community built the type class pattern, a way of adding behaviour to existing classes without inheritance, which runs through its third-party libraries.[2] Mastering Advanced Scala works up to it through the less familiar corners of the language: type erasure on the Java virtual machine and the class tags that carry type information to run time, and existential types, first introduced for interoperation with Java.[2] Scala from Scratch: Understanding covers the same pattern together with variance, algebraic data types and functional error handling.[15]

Functional programming

Much of the writing on Scala is about functional programming carried further than the standard library takes it, and the books follow the libraries that did so. Functional Programming for Mortals is built on Scalaz: it goes through that library's hierarchy of type classes and data types in detail and ties them to one application that is specified, tested and assembled over the course of the book.[11] Mastering Advanced Scala uses Cats to illustrate the abstractions of category theory and treats Scalaz mostly as an improvement on the standard library, with shorter treatments of libraries for generic programming, optics, JSON, HTTP and database access.[2] Its method is to use the existing libraries and not to rebuild the abstractions from nothing.[2]

The next step is the effect: a description of an action such as a network call, kept as a value until the program runs it. Practical FP in Scala builds a shopping-cart service with an HTTP interface, a database and a cache on Cats Effect and the libraries around it, and follows it from business requirements through persistence and testing to a container image and a build pipeline.[4] Effect Oriented Programming presents effects as a paradigm in their own right, with Scala 3 and ZIO for its examples, and organises its chapters around what an effect system allows: retrying, timeouts, fallbacks and finalisation.[12] Both are cited from their contents and prefaces; the first book's sample holds its table of contents and preface, and the second has no sample.

The Science of Functional Programming (2025) stands apart as theory. It is a long tutorial and reference on the mathematics behind functional programming, with derivations of the laws of type classes and of monad transformers, and its examples are in Scala, though its author notes that most of the material applies to other functional languages equally.[9]

Web development

The web books show the range the language's community covers. Play is the approachable end: a framework modelled on Rails, which one author recommends to newcomers as a way of learning Scala while building something.[2] His Modern Web Development with Scala does exactly that, covering a little of each part of an application from database access to front-end tooling and deployment.[3] Developing Web Applications (2025) starts where such a book stops. It does not teach Play, sends the reader to the framework's own documentation, and dissects one deployed open-source application built with the ports-and-adapters pattern; its author describes it as work in progress.[7]

Akka HTTP is a lower-level toolkit for services. Akka HTTP RESTful APIs (2020) builds a bookstore interface with it step by step, with a relational database, schema migrations and authentication, writing tests first and explaining each tool only when the project needs it.[6] Pure functional HTTP APIs in Scala sets the two styles side by side: it implements one service specification twice, once in the customary impure style on Akka HTTP and once in a pure style on http4s, and then tests and benchmarks the two.[13]

Architecture in Scala

Several books use Scala as the language for an architectural pattern. Event sourcing records the state of a system as a series of events instead of keeping only the current state, which yields an audit trail and a history that can be analysed later.[5] Practical Event Sourcing with Scala (2021) treats it as a technical pattern for an ordinary web application, a question-and-answer site, and leaves domain modelling aside; its author chose Scala as a middle course between heavier and terser languages.[5] Event Sourcing in Scala (2026) is the advanced counterpart in Scala 3 and ZIO, with a relational database as the system of record: events as sealed families of types, state as a fold over history, and commands as functions that enforce the rules.[16]

The same author's Saga Architecture in Scala (2026) addresses workflows that span several services, where one transaction cannot cover everything and partial failure is normal. It builds an order-placement flow twice, once directed by a central orchestrator and once by services reacting to each other's events, with compensating actions to undo completed steps.[17] Layerd FP in Scala (2026) treats clean, hexagonal and onion architecture as one family of ideas and uses the build tool's modules so that the compiler enforces the direction of dependencies.[18] None of the three has a sample.

Data and artificial intelligence

Many programmers meet Scala through Apache Spark, the distributed data-processing engine written mostly in it.[1] Spark Tutorials with Scala (2016) is a set of short tutorials that run Scala in Spark's interactive shell, starting with its original collection type and the difference between transformations and actions; it targets a version of Spark long superseded.[10] Testing Spark Applications (2020) covers a narrower need, test suites for Spark code: comparing columns and data frames, testing code that reads and writes files, and keeping a suite fast.[20]

Practical Artificial Intelligence With Scala (2026) is the one book on artificial intelligence. Each chapter is a small self-contained Scala 3 project, from classical search and neural networks written from first principles to clients for hosted and local language models, retrieval-augmented generation and agents that call tools.[19] It is cited from its description.

Tools

A Scala installation begins with a Java development kit, since the compiler and the programs it produces run on the Java virtual machine.[3] The interactive shell, in which expressions are typed and evaluated at once, is the usual first tool, and the masterclass recommends a separate launcher for installing and managing compiler versions.[1]

Three build tools are in use. sbt is the most widely used; its build is itself written in Scala and it keeps the build loaded between commands, which makes repeated compilation fast. Mill is newer, with quicker start-up and plainer build definitions and fewer plugins. Bloop is a build server that either can use to keep the compiler running.[1] The masterclass calls sbt the safest choice for a new project.[1] The older books show the same tools at earlier versions, together with the editors and operating systems of their day, and are best read for the language and the design of their projects.[6][3]

Scalapedia (2026) gathers the whole of this ground into a reference in ten parts, from the basics and Scala 3 through the Cats and ZIO libraries to patterns, performance and web frameworks, with questions and answers for interview preparation. Its description says it was translated into English and edited with the assistance of AI.[21]

Questions about Scala

Which Scala book should I start with?

A programmer coming from another language can start with Scala from Scratch: Exploration (2020), the first of two volumes, or with Scala Masterclass: From Fundamentals to Advanced Patterns (2026), which is written in Scala 3 syntax.[14][1] A web developer can learn the language while building an application with Modern Web Development with Scala (2020).[3]

What is the difference between Scala 2 and Scala 3?

Scala 3, released in May 2021, is a redesign of the language meant to reduce accumulated complexity, the largest change since version 2.0.[1] Books from 2021 and earlier use Scala 2 and its implicit syntax, and the books of 2026 are written for Scala 3.[2][16]

Is Scala object-oriented or functional?

Both. Every value is an object and every function is a value, and most programs blend the two styles, with case classes for data, traits for shared behaviour and higher-order functions for transforming collections.[1]

What is a type class in Scala?

A type class is a pattern for adding behaviour to existing classes without inheritance.[2] In Scala 2 it is built on implicit values, which the compiler finds in scope or in the companion objects of the types involved, and it runs through the community's third-party libraries.[2]

Should I use Cats or ZIO?

The books do not rule between them, and each library has books built on it. Practical FP in Scala builds a complete service on Cats Effect, and Effect Oriented Programming teaches effects with ZIO.[4][12] Pure functional HTTP APIs in Scala compares a different pair, implementing one service in an impure style and a pure one and benchmarking the two.[13]

Do I need Scala to use Apache Spark?

Spark is written mostly in Scala, and one introduction is addressed in part to data engineers who need the language for that reason.[1][8] The Spark books in this library work in Scala, one in the interactive shell and one on test suites.[10][20]

Sources

Every source is a Leanpub book or course. The note after each says which part of it was read; where no sample was available, only the public description and table of contents were used.

  1. 1.
    Scala Masterclass: From Fundamentals to Advanced Patterns, Steve Publications: A Comprehensive Guide to Modern Scala Programming Free sample: chapter 1 on the language's origins, versions and use, and part of chapter 2 on installation, the interactive shell and build tools. 2026. Free sample: PDF · EPUB
  2. 2.
    Mastering Advanced Scala, Denis Kalinin: Exploring the deep end of functional programming Free sample: the preface and the opening chapter on implicits, type erasure, existential types and the type class pattern. 2020. Free sample: PDF · EPUB
  3. 3.
    Modern Web Development with Scala, Denis Kalinin: A concise step-by-step guide to the Scala ecosystem Free sample: the preface, the setup of tools and the first part of the language tutorial. 2020. Free sample: PDF · EPUB
  4. 4.
    Practical FP in Scala, Gabriel Volpe: A hands-on approach Free sample: the table of contents and the preface. 2021. Free sample: PDF
  5. 5.
    Practical Event Sourcing with Scala, Denis Kalinin: A comprehensive example based on Scala, Play and Akka Streams Free sample: the preface, the setup of tools and the start of the project. 2021. Free sample: PDF · EPUB
  6. 6.
    Akka HTTP RESTful APIs, Codemunity: Building Reactive RESTful APIs with Scala and Akka Free sample: the introduction, the project setup and the conclusion. 2020. Free sample: PDF · EPUB
  7. 7.
    Developing Web Applications, Paul E. Sevinç: with Play & Scala Free sample: the preface, prerequisites and tools, and the start of the chapters on access control and security; most chapters are withheld. 2025. Free sample: PDF · EPUB
  8. 8.
    Scala For Beginners, Nadim Bahadoor Free sample: the preface and outline only. 2019. Free sample: PDF · EPUB
  9. 9.
    The Science of Functional Programming, Sergei Winitzki: A tutorial, with examples in Scala Free sample: the front matter, the book's description and the table of contents. 2025. Free sample: PDF
  10. 10.
    Spark Tutorials with Scala, Todd McGrath: The Beginner's Guide Free sample: the introduction to Spark and its first tutorial in the interactive shell. 2016. Free sample: PDF
  11. 11.
    Functional Programming for Mortals, Sam Halliday: with Scalaz No sample: from the description and table of contents. 2026.
  12. 12.
    Effect Oriented Programming, Bill Frasure, Bruce Eckel, James Ward: A Paradigm for Creating Reliable, Adaptable, Testable Systems - Using Scala and ZIO No sample: from the description and table of contents. 2024.
  13. 13.
    Pure functional HTTP APIs in Scala, Jens Grassel No sample: from the description and table of contents. 2022.
  14. 14.
    Scala from Scratch: Exploration, Daniel Westheide No sample: from the description and table of contents. 2020.
  15. 15.
    Scala from Scratch: Understanding, Daniel Westheide No sample: from the description and table of contents. 2020.
  16. 16.
    Event Sourcing in Scala, Piotr Pruchniewicz: Scala 3, ZIO, PostgreSQL and the log beyond the database No sample: from the description and table of contents. 2026.
  17. 17.
    Saga Architecture in Scala, Piotr Pruchniewicz: Functional Saga Architecture in Scala 3 and ZIO No sample: from the description and table of contents. 2026.
  18. 18.
    Layerd FP in Scala, Piotr Pruchniewicz: Clean Architecture, Hexagonal and Onion with Scala 3 and ZIO No sample: from the description and table of contents. 2026.
  19. 19.
    Practical Artificial Intelligence With Scala, Mark Watson: Practical AI Code in Scala No sample: from the description and table of contents. 2026.
  20. 20.
    Testing Spark Applications, Matthew Powers: Writing Spark code is hard... well designed, performant Spark tests are even harder. You need a robust test suite to identify performance bottlenecks in your code and refactor with ease. This book teaches you how to write a beautiful test suite and how to run the tests whenever code is pushed to the master branch. No sample: from the description and table of contents. 2020.
  21. 21.
    Scalapedia, Piotr Pruchniewicz: Encyclopedia of the Scala programming language No sample: from the description. 2026.

Further reading

Other books in the library on the same ground, not cited above.

  • A Language a Day, Andrew Shitov: A brief introduction to 21 programming languages: C++, Clojure, Crystal, D, Dart, Elixir, Factor, Go, Hack, Hy, Io, Julia, Kotlin, Lua, Mercury, Nim, OCaml, Raku, Rust, Scala, and TypeScript Short introductions to twenty-one programming languages, Scala among them, each solving the same small problems. 2024. Free sample: PDF
  • Scala for Apache Spark, Prashant Mhatre Brief, unfinished notes on the Scala needed to begin programming Spark. 2017.

This is an article created from the free samples of 10 Leanpub books and the descriptions and tables of contents of 11 more. We're building these articles to provide you, the Leanpub reader, with a good jumping-off point to discover more Leanpub books that are interesting and relevant to you. We never use material which is paid-only when building these articles: we only use material which is already free on Leanpub. However, Leanpub authors can opt out from inclusion in articles from their book settings page.

Updated November 2026.

In the Leanpub store: 32 books in the Scala category

All topics