Leanpub Header

Skip to main content

Topics

Functional Programming

From pure functions, immutable data and composition to algebraic types, monads, optics and type-level design, in Haskell, PureScript, Elm, Scala, Clojure, Elixir and F# and in the mainstream languages that borrowed from them, functional programming as told through the free samples of the Leanpub books about it.

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

Functional programming is a way of building programs out of functions in the mathematical sense: expressions that compute a value from their inputs and do nothing else. Its working parts are pure functions, data that is never changed once made, functions that take and return other functions, and composition, by which small functions are joined into larger ones. One source borrows a line that fits the whole contrast: object-oriented code is made understandable by encapsulating its moving parts, functional code by having fewer of them.[16] The procedural and the functional ways of describing a computation were both worked out in the 1930s and can solve the same problems; which is easier to write, read or run varies from one problem to the next.[18]

The field today runs on two tracks. One is the languages designed around the style: Haskell, PureScript and Elm, Scala, Clojure, Elixir on the Erlang virtual machine, F# on .NET. The other is the mainstream languages that have been taking the style's features in: lambdas and streams in Java, arrow functions and modules in JavaScript, short lambdas in PHP 7.4. One source observes that every language is gaining functional features and argues that what functional programmers value is not the features one by one but the way an approach to writing software and the features work together;[45] another argues that writing PHP as if it were Haskell produces a poor result, while the principles underneath functional programming help even there.[18] A good part of the library is given over to explaining the vocabulary the style took from category theory, functors and monads above all, and several of the books exist because their authors found every earlier explanation wanting.[15][18]

This article runs from where to begin, through the history and the ideas themselves (purity and composition, algebraic data types, monads, optics), to types as a design tool, the languages one by one, the mainstream languages that borrowed from them, and designing and shipping whole applications in the style. Its sources are the free samples of the Leanpub books listed at the end, with the descriptions and tables of contents of the books whose samples were not available, and every claim that rests on a source is cited to it.

Where to start

Three sources assume no functional programming and little else. Happy Learn Haskell Tutorial Volume 1 (2022) assumes no programming experience at all and has the reader read many small example programs before writing any, holding words such as monad and lambda calculus back until enough examples have been seen; its free sample runs through its first five chapters, from values and types to functions that return functions.[3] Functional Programming Made Easier (2021) starts from nothing in PureScript, alternates lecture chapters with lab chapters, and ends with a working backend and browser front end; its author says the book assumes the reader knows nothing about functional programming.[37] An Outsider's Guide to Statically Typed Functional Programming (2018) asks only that the reader be a programmer and teaches the statically typed kind of functional programming in Elm first and PureScript second, because Elm is, in the author's view, the friendliest of the static functional languages and PureScript the gentlest way into the more mathematical parts.[1]

A developer who already works in another language has a book written from that side. Functional Programming for the Object-Oriented Programmer (2015) takes programmers who know any object-oriented language into Clojure, building an object system out of functions and maps first so that they meet their own tools from the other side.[33] Functional-Light JavaScript (2018) teaches the core principles in JavaScript with as little terminology as it can manage, introducing a term only when it is needed, for readers put off by the jargon.[14] An Elm Primer for React Developers (2026) is for React developers and calls Elm the shortest path to learning functional programming, because the language is small and the domain, web user interfaces, is one the reader already knows.[26] Thinking Functionally in PHP (2021) asks for working PHP and nothing else;[18] Functional programming in Modern Java (2026) asks for working Java;[20] Essential F# (2023) sets up F# in VS Code and runs from a domain modelling exercise to a web API;[45] and The Haskell Blueprint (2026) asks for one mainstream language such as Python, Java or JavaScript and promises Haskell for real software rather than theory.[39]

The specialist books say plainly whom they are not for. Thinking with Types tells a beginner who finds GHC's type errors inscrutable that the book is not for them yet;[2] Book of Monads asks for basic typed functional programming in Haskell, Scala, F# or OCaml;[4] The Science of Functional Programming is a long mathematical tutorial with derivations and proofs;[30] Pragmatic Type-Level Design assumes comfort with a statically typed language with generics and type classes;[13] Practical FP in Scala is for Scala developers who already understand functional effects;[36] Functional Programming for Mortals sends beginners to a Scala textbook first;[44] and Production Haskell is for people who know the language and want to ship with it at work.[6]

History

The functional style is as old as the theory of computation. The lambda calculus and the procedural model of a machine stepping through instructions were developed within a few years of each other in the 1930s and shown to be equivalent, as one source recounts, so that nothing solvable in one is unsolvable in the other.[18] Lisp, which Clojure descends from, is one of the oldest programming languages still in use.[33] A foreword in one source traces the lineage of designing programs around algebraic laws from Landin and Backus through Guttag and Horning to functional geometry, pretty-printing libraries and the QuickCheck and QuickSpec tools.[12]

For most of that time the style lived in universities. One source describes it as initially popular only among researchers and gaining traction in industry in recent years;[40] another notes that Haskell still carries a reputation for being academic, exotic and impractical while running in production at financial institutions and technology companies.[39] Scala's path is dated more precisely: the language emerged in 2004, was known to a small circle, and became a business technology after Twitter rewrote part of its core in it in mid-2008, with Foursquare, LinkedIn and Tumblr following.[24] A Haskell practitioner's account of the same period is less rosy: the language primarily serves academia as a research language, industrial use is a secondary concern, and many of its practitioners are hobbyists whose techniques do not always transfer.[6]

The mainstream caught up feature by feature. Java took lambdas and streams in Java 8 and records, sealed types and pattern matching later;[32] JavaScript's ES2015 brought the destructuring, generators and classes that one source builds its function-first treatment of the language around;[43] PHP 7.4's short lambdas were, by one author's account, the change that made a functional PHP book worth writing.[18] Elm, by contrast, has had no release since 2019, a fact one of its advocates reports without alarm.[26] One source argues that functional programming has still not won because nobody teaches how to design whole applications in it, and offers law-driven design as the missing piece;[12] another calls its subject the theory of functional programming as practised at the beginning of the twenty-first century.[30]

The ideas

The books agree on a small core of ideas and differ in how much mathematics they attach to it. The subsections below take the ideas in the order the beginner books do: pure functions and composition first, then the types that describe data, then the abstractions built over those types, then optics.

Pure functions, immutability and composition

A side effect, in one source's list, is anything a function does beyond computing and returning a value: writing to a database, making an HTTP call, writing a file, printing, changing a global variable, throwing an exception. A function that only adds two numbers is pure; one that saves a user and logs it is not.[19] The case against mutable shared state is made at length in a Java book: an order object whose items can be changed by anyone holding a reference, whose total can be read stale from another thread, and whose setters merely redistribute the problem rather than removing it. Functional programming, it concludes, is a set of practical techniques for managing that complexity, not a religion: immutability makes concurrency safe, pure functions allow local reasoning, composition allows reuse, and testing becomes input, function, output.[20] A JavaScript author reaches the same place from the other end, writing objects as literals that return a new instance on every operation so that immutability is forced, while warning that purity should not be an end in itself.[16] In Haskell everything is pure by construction, which one tutorial devotes a chapter to explaining with an analogy before the reader has written much code.[3]

Composition is the mechanism that makes small pure functions add up. Functional-Light JavaScript builds it from a two-function helper to a general compose over any number of functions, by way of a candy-factory analogy, and pauses on the point that trips most readers: the functions execute right to left, but they are listed left to right, matching the order in which they appear when the calls are nested by hand. Partially applying compose itself, the book shows, yields a family of specialised pipelines from one shared prefix.[14] Composing Software takes the widest view: all software design is composition, breaking a problem into smaller problems and composing the solutions, and it treats function composition and object composition as two forms of the same thing.[46] JavaScript Allongé, the "Six" Edition arrives at classes, mixins and decorators by building them from closures, combinators and partial application.[43] What functional and procedural programming share, one source notes, is dividing a program into reusable chunks; what the functional style adds is making those chunks values that can be created, passed around and stored.[18]

Names are the other half of composition. Elements of Clojure treats a name as a layer of indirection separating what a function does from how, and observes that software is written one name at a time, so that programmers may create more names than any other profession; it borrows Frege's distinction between a name's referent and its sense to explain why two variables bound to the same value today are kept separate when they are expected to diverge.[28]

Algebraic data types and pattern matching

Functional languages describe data with sum types (one of several alternatives) and product types (several things together), and take it apart with pattern matching. Thinking with Types calls pattern matching over algebraic data types one of the style's killer features and then takes the word algebraic literally, counting a type's inhabitants and showing that Either adds, pairs multiply and functions are exponentials.[2] The Science of Functional Programming covers the same ground as disjunctive types and goes on to the Curry–Howard correspondence between types and logical propositions.[30] In Scala the mechanism is visible: a case class gets a companion object with an apply method that constructs and an unapply method that extracts, and The Neophyte's Guide to Scala shows how to write extractors by hand for classes that are not case classes, noting that pattern matching is equally central in Haskell and Erlang.[22]

The practical payoff is what the compiler will refuse. An Elm Primer for React Developers opens with a case expression that forgets one of three animals and prints the compiler's reply, which lists the missing possibility and says it would have to crash on it; the author contrasts that with the helper functions TypeScript developers write to get the same check.[26] An Outsider's Guide to Statically Typed Functional Programming makes the general argument through affordance: a typical language gives no good reason to handle an empty list that cannot happen, whereas a static functional language lets you build a list that cannot be empty, turning what you believe into what the compiler guarantees.[1] The Simple Haskell Handbook does exactly that in its first pages, replacing the plain lists of steps and commands in a continuous integration server's model with non-empty lists, and models the build's progress as a state machine, a function from the old state to the new one.[8]

The same types replace null and exceptions. Finding Success (and Failure) in Haskell grows one password validator through Maybe, Either, newtypes, Applicative and a Validation type, motivated by the wish to report every error in a form rather than halting at the first.[5] Essential F# covers option and result types, discriminated unions and active patterns as the everyday tools of a line-of-business F# codebase.[45] In Java, Functional programming in Modern Java reaches records, sealed types and a chapter titled on the premise that null is not a feature.[20]

Functors, monads and their friends

No topic in the library has more books devoted to it than the monad, and most of them open by admitting it. Unwrapping Monads & Friends calls writing a monad tutorial a rite of passage and defines the thing in two JavaScript functions, an Identity wrapper and a chain operation, before stating the three laws; a monad, it says, is a pattern rather than a thing, and its instances are what programs contain.[15] Thinking Functionally in PHP names the curse: whoever understands monads becomes unable to explain them, and the terminology varies so much between tutorials and languages that the variation is itself an obstacle to learning.[18] Functional-Light JavaScript opens its preface with the famous one-line definition in terms of monoids and endofunctors and promises never to teach it that way.[14]

The thorough treatments take the opposite approach. Book of Monads runs to five parts: what a monad is and its laws; the State, Reader and Writer monads and monads for failure, logic, mutability, resources and continuations; combining monads with transformers; defining your own, including free and freer monads and extensible effects; and finally the category theory behind the one-line definition, with most code in both Haskell and Scala.[4] The Science of Functional Programming proves that the standard monads satisfy their laws, derives lawful instances of Functor and other type classes from the shape of a type, and reports that monad transformers need eighteen laws.[30] Functional Programming in Javascript maps the vocabulary onto JavaScript, with Identity, IO and Maybe functors built as object literals following the Fantasy Land conventions and brief TypeScript asides for the types;[16] its TypeScript edition starts instead from lenses and monoids, showing a Sum monoid and parenthesis balancing before algebraic data types and functors, and points to the purify and fp-ts libraries for production use.[17] Asynchronous functional javascript applies the same structures to concurrency, treating callbacks as continuation-passing style and promises as a functor and a monad after a tour of the event loop.[21]

On the JVM the abstractions arrive as libraries. Mastering Advanced Scala explains implicit parameters and conversions, type erasure and the type class pattern as the groundwork, then tours ScalaZ and Cats: monoids, functors, monads, transformers, Reader, Writer, State and Free, starting with ScalaZ's disjunction as an alternative to Either and Try.[23] Functional Programming for Mortals builds the same material on Scalaz for the sceptical Scala developer with a Java background, with a web application as the running example.[44] In Clojure, Functional Programming for the Object-Oriented Programmer introduces monads in a chapter on avoiding if expressions and keeps two further chapters on them optional.[33] For Haskell, Haskell (almost) Standard Libraries maps the abstractions to packages, with chapters on functors, transformers and effect systems alongside mtl and rio.[9]

Optics

Optics are the functional answer to reading and updating a value deep inside an immutable structure. Optics By Example defines them as a family of inter-composable combinators for bidirectional data transformations, with lenses, folds, traversals, prisms and isos as the main kinds, and lists what they buy: composition, since each optic picks up where the previous one left off; separation of the choice of data from the operation on it, which the author offers as a replacement for the visitor pattern; concision, illustrated by a one-line sum over the costs in a JSON document; and a stable interface over a changing data layer. Its weaknesses are listed as honestly: ugly type errors, and implementations that differ between the Haskell, Scala and PureScript libraries.[10] Lenses for the Mere Mortal: PureScript Edition teaches the same material in PureScript organised by the kind of data rather than the kind of optic, insists on the word optic for the idea and lens for one type, and starts with view, set and over on tuples and records.[35]

Outside Haskell the idea travels well. Functional Programming in TypeScript presents lenses as functional getters and setters, extracting a class's getter into a standalone function so that it can be mapped over a list of clients and composed point-free.[17] Functional programming in Modern Java devotes two parts to lenses, prisms and traversals built from records and sealed types.[20] Clojure's equivalent for nested data is the Specter library, whose selectors go beyond get-in to select or transform many leaves at once and to walk code; Extending and Using Specter teaches it by having the reader rebuild its API on a navigator protocol.[29] Composing Software covers lenses and transducers in JavaScript,[46] and Haskell (almost) Standard Libraries lists the optics packages and the ones that focus on JSON documents.[9]

Types as a design tool

In the statically typed languages the type checker is a design instrument, and the library disagrees about how hard to lean on it. Thinking with Types states the type-level programmer's aim as preventing code from compiling, so that the compiler rejects more wrong programs, and in the same introduction counsels moderation: the techniques have their own complexity, are worth it for a financial application and not for a hobbyist game, and when in doubt the job should be done with values. Its motivating example is C's printf, whose argument types depend on a string and whose unchecked calls are a classic security hole.[2] Pragmatic Type-Level Design compares type-level code to Conway's Game of Life, where simple rules produce complexity that is hard to predict and a single misplaced cell wrecks the pattern, and argues that type-level programming should become engineering rather than art, with design patterns and a methodology, deliberately without category theory or type theory, and with a Rosetta Stone restating the ideas in Rust and Scala 3.[13] The sceptical note comes from Production Haskell: safety features forbid invalid programs, and when requirements change so does the notion of an invalid program, so every safety feature narrows the options later.[6]

Beyond Haskell's extensions lie the proof assistants and the total languages. Certainty by Construction teaches Agda from scratch and treats mathematics as the goal and Agda as the tool, moving by its contents from natural numbers and induction through equality, relations, decidability and isomorphisms to the algebra of algebraic data types, and proposing abstract algebra as a basis for software design.[38] Programming in System Fω using Dhall works inside Dhall, treated as an interpreter for System Fω: total, with no side effects and no general recursion, so that recursive types, type classes and dependent-type tricks have to be encoded with Church encodings.[31] The Science of Functional Programming shows practical uses of the Curry–Howard correspondence and of parametricity, with 1,982 code snippets, 233 step-by-step derivations and 315 exercises.[30]

A gentler use of types is to put the laws of a design into tests. Algebra-Driven Design designs programs around algebras, laws that the operations must satisfy, and derives implementations and property-based tests from them, with reference chapters on QuickCheck and QuickSpec and on the common algebraic structures, from associativity and identity to semigroups, monoids, groups, semilattices and functors.[12] Java Backend Coding Technology takes the engineering version of the idea into Java: four return types that state whether a step can fail, may be absent or runs asynchronously, value objects that parse rather than validate, typed errors instead of exceptions, and five named criteria (mental overhead, business-to-technical ratio, design impact, reliability, complexity) for arguing every decision, with the stated aim that different developers, or AI assistants, produce nearly identical code from the same requirements.[19] Practical FP in Scala opens with the same tools at a smaller scale, newtypes and refinement types as best practices before the project begins.[36]

The languages

Six language families account for most of the library, and the books on each divide into tutorials, idiom guides and project books.

Haskell

The Haskell shelf is the deepest and the most candid. Production Haskell is the view from industry: managing complexity is the most important and difficult task in a Haskell project, which it says twice; a project has a complexity budget and a novelty budget, spent on fancy and on unfamiliar technology respectively, and choosing Haskell has already spent much of both; and the community's tolerance for complexity comes from the confidence that strong types give. Its parable of two cars ends with the advice to take the slow one that fails predictably if you need to get to work.[6] The Haskell Blueprint answers the reputation for impracticality with an engineering-first guide that runs from functions and type classes to Cabal, Hspec testing and deployment and ends with a complete blog engine on a hexagonal architecture.[39]

The project books each pick one substantial thing to build. Sockets and Pipes starts from the question of what exactly a web server is, implements HTTP from file handles and bytes up through sockets, following the RFC 9110 and 9112 definitions, and takes in monad transformers, resource safety, streaming and typed errors on the way; it needs GHC 9.2 or 9.4 and ships a companion package that re-exports every library it uses.[7] The Simple Haskell Handbook builds a continuous integration server that runs its steps in Docker containers, in a deliberately restricted subset of the language, and shows the refactoring rather than hiding it; after the domain model it moves to the Docker Engine API, JSON, dependency injection, tests, STM and a CLI.[8] Haskell (almost) Standard Libraries exists because Haskell's base library is slim: it surveys the community's preferred packages by task across twenty-five chapters, from containers, text and bytes to parsing, optics, streaming, async, STM and web applications, with a one-page summary mapping tasks to packages.[9]

The tutorials span the whole range. Happy Learn Haskell Tutorial Volume 1 takes a complete beginner through values, types, IO, purity and functions that return functions;[3] Finding Success (and Failure) in Haskell grows one program from case expressions to applicative validation;[5] Optics By Example and Thinking with Types are the advanced references on optics and on type-level programming;[10] and Functional Design and Architecture (Early Edition, 2020), an early edition its author has since reworked for another publisher, opens with the case that software design matters as much in Haskell as anywhere and sets out two projects, a spaceship control simulator and a web-service framework, to show it.[11]

PureScript and Elm

Two Haskell-shaped languages compile to JavaScript. PureScript, in the words of PureScript by Example, is a small, strongly and statically typed language inspired by Haskell, made to bring disciplined functional programming to large JavaScript applications; its chapters are each motivated by a problem, an address book, canvas graphics, a text adventure, and introduce applicative validation, effect monads, monad transformers and free monads in solving them, though its tooling chapter dates from 2017.[42] Functional Programming Made Easier is the long beginner's path through the same language, from functions and type classes to effects, a JSON library, the foreign function interface and a full-stack application with HTTPure and Halogen.[37] Lenses for the Mere Mortal: PureScript Edition assumes only shallow PureScript and teaches optics in it.[35]

Elm trades features for focus. An Outsider's Guide to Statically Typed Functional Programming credits it with the best error messages, documentation written in plain language and a read-eval-print loop that tries not to surprise, but notes that it offers very limited polymorphism, which is why the book moves on to PureScript to show what is missing.[1] An Elm Primer for React Developers presents the trade from the React side: exactly one architecture, the Elm Architecture of a model, an update function and a view; exactly one way to represent side effects; and a compiler strict enough that a program that compiles is very likely to work. It is frank about the costs, a smaller ecosystem, a learning curve and hiring, and shows how to adopt the language one widget at a time inside an existing React application.[26]

Scala

Scala's books divide by how functional they want the language to be. Modern Web Development with Scala is the pragmatic end: it dates the language's rise to Twitter's 2008 rewrite, describes Scala as high-level syntax without the performance cost, and teaches it by building a Play application with one chapter on functional concepts along the way, on Scala 2.13 and Play 2.8.[24] The Neophyte's Guide to Scala picks up where a first course leaves off, with the everyday idioms (extractors, Option, Try and Either, futures, type classes) in sixteen articles that date from 2012 and 2013.[22] Mastering Advanced Scala names Play as the approachable framework a newcomer should start with and then goes where that book does not, into implicits, type classes and the purely functional libraries.[23]

The purely functional end has its own canon. Functional Programming for Mortals is written for the sceptical Scala developer with a Java background and builds a web application on Scalaz, with for comprehensions, algebras, type class derivation and advanced monads on the way.[44] Practical FP in Scala takes a shopping cart service from design through its HTTP layer, persistence and cache to testing and a Docker image with continuous integration, on Cats Effect, Fs2, Http4s and Skunk.[36] Pure functional HTTP APIs in Scala specifies one small web service and implements it twice, first with Akka HTTP and Slick and then purely with Cats Effect, http4s and Doobie, so that models, routes, tests and benchmarks can be compared side by side; its second edition migrates the project to Scala 3.[47] Effect Oriented Programming is the ZIO introduction, framing network calls, user input and failure as the effects that make software unpredictable and showing retries, timeouts and fallbacks before the machinery.[48] Scalapedia is a 746-page reference across the whole ecosystem, edited with AI assistance by its own account,[51] and The Science of Functional Programming uses Scala for its examples while saying that most of its material applies to any functional language.[30]

Clojure

Clojure is the library's Lisp. Functional Programming for the Object-Oriented Programmer describes it as a small core surrounded by many library functions, running on the Java virtual machine (which is why the REPL takes a few seconds to appear), and uses it to teach object-oriented programmers the elements of functional style: data flowing through functions, functions that make functions, laziness, zippers and pattern matching.[33] Foundations of Clojure covers the language's core in order, from functions and threading expressions through sequences, destructuring and control structures to managed state with atoms and refs, macros, namespaces and polymorphism.[49]

The two short essays on the shelf are about judgement. Clojure Polymorphism solves one data-transformation problem three ways, as a plain function with a cond, a multimethod and a protocol, and compares them for flexibility, performance, external integration and cross-platform code; its principles include never extending an abstraction you do not own to a type you do not own, letting library users pass in a function rather than defining a multimethod or protocol for them, and reaching for protocols as the usual balance.[27] Elements of Clojure is about names, idioms, indirection and composition, written for people who know the language but struggle to explain their design decisions.[28] Extending and Using Specter is the one library guide, for working with nested data.[29]

Elixir and the BEAM

The Elixir books in the library are application books rather than language books, so the functional ideas appear in use. Toy Robot - The Elixir Version works the Toy Robot interview exercise from a Mix application through pattern-matching styles, ExUnit tests and doctests to a command interpreter and a command-line interface, then turns it into a supervised multiplayer game with GenServer and DynamicSupervisor.[57] Building Conduit builds a blogging platform in Elixir and Phoenix with command query responsibility segregation and event sourcing on the Commanded library, with aggregates, domain events and read-model projections.[58] Phoenix Product Codex follows the author building a product-data REST API for a family industrial-equipment business, on Elixir 1.18 and Phoenix 1.7, modelling suppliers, brands and variants with Ecto changesets and generating typo-resistant item codes with a Markov chain; it is a work in progress by its own notice.[41]

F#

Essential F# is the one F# book, free, and grown from blog posts on a company's website: the core of what a developer needs to work on one of its line-of-business codebases, from domain modelling and functions through null and exception handling, collections, recursion and computation expressions to three chapters on web programming with Giraffe, with the code upgraded to F# 5 and run in VS Code with the ionide extension.[45]

Functional programming in mainstream languages

The second track of the field is the books that apply the style inside languages not designed for it. They are the most read on the topic, and they share a tone: adopt what helps, and keep the rest.

JavaScript and TypeScript

JavaScript has functions as values and closures built in, and its books argue about how far to go. Functional-Light JavaScript draws the line at what it calls functional-light programming, a subset the author reached pragmatically and experientially rather than academically, covering function inputs, composition, side effects, immutability, closures versus objects, recursion, list operations and async, with transducers and monads in appendices and library versions from 2017 and 2018.[14] JavaScript Allongé, the "Six" Edition starts from values and expressions and builds the language's classes and mixins from functions, for ECMAScript 2015.[43] Composing Software covers pure functions, currying, functors, monads, object composition, factory functions, mixins, lenses and transducers, and began as a series of blog posts.[46] Unwrapping Monads & Friends builds Identity, Maybe, Reader, State and IO in plain JavaScript using the Monio library for examples, and is free to read online under another title.[15] Functional Programming in Javascript and Asynchronous functional javascript are the category-theory treatments, the second one still visibly in progress in its sample.[21]

TypeScript adds the types. Functional Programming in TypeScript builds the structures by hand in typed code and names purify and fp-ts as the two mature libraries for production use.[17] Multi-Paradigm Programming uses TypeScript to argue that functional, object-oriented and imperative styles belong together, treating iterators, generators and Lisp's code-as-data as one idea and applying it to asynchronous code and front-end applications; its first three chapters are published on GitHub.[50] An Elm Primer for React Developers is the book for a TypeScript developer who wants to see what the discipline looks like when the compiler enforces it.[26]

Java

Java's functional books are recent and practical. Functional programming in Modern Java covers Java 8 through 25, from the case against mutable shared state through immutability, pure functions, composition, records and sealed types, null handling and streams to error handling without exceptions, containing side effects and optics.[20] Java Backend Coding Technology presents a complete coding methodology for Java 21 and later backends, with six structural patterns and a supporting library, aimed at teams whose code is written by humans and AI assistants together.[19] Modern Java: Second Edition places the lambdas, streams, records and pattern matching in the wider history of a language first developed in the 1990s and owned by Oracle since 2010, and counts Groovy and Scala among the other languages that compile to its bytecode.[32]

PHP, Go and Fortran

Thinking Functionally in PHP is the most complete of the single-language treatments: four parts covering pure and first-class functions, immutability and recursion; the category theory underneath, functors, monads and algebraic data types; applying Maybe and Either to null handling and errors; and a survey of functional-language features with advice on when to go functional. It is tied to PHP 7.4, whose short lambdas prompted it, and it classes PHP with C++, Java and C# as class-based object-oriented languages.[18] A Go Developer's Notebook is an exploratory Go book, in pre-generics Go, with functional programming as one part among networking, encryption, caching and concurrency.[34] Modern Software Design in Fortran redesigns Fortran code with ideas from contemporary paradigms, including a chapter on functional programming beside derived types, polymorphism and test-driven development, in a language without exceptions.[56]

Designing and shipping functional applications

The books in this last group assume the reader knows the style and ask how to build and run something with it.

Architecture and design

Functional Design and Architecture (Early Edition, 2020) sets out a methodology its author calls Functional Declarative Design, built on hierarchical free monads, and divides its material into an introduction, domain-driven design and designing real-world software, with requirements, layering, embedded domain-specific languages, state, concurrency, persistence and testing covered through two projects; the author says the second project's ideas have been tested in production.[11] Layerd FP in Scala treats Clean Architecture, hexagonal ports and adapters and the onion model as one family of ideas, dependencies pointing inward and technology at the edges, and enforces the rule in real Scala 3 modules for a SaaS billing domain whose core has no effect system in it at all.[55] The Haskell Blueprint ends on the same shape, a blog engine on hexagonal architecture and domain-driven design.[39] Algebra-Driven Design argues that this is the missing discipline, and Production Haskell adds the organisational side: selling the language, hiring for it, the ReaderT pattern for application structure and the cost of every novelty.[6]

Effects, services and event-driven systems

The Scala shelf carries the library's distributed-systems work. Functional Event-Driven Architecture builds a trading system in purely functional Scala 3 on Apache Pulsar and Fs2 streams, with a WebSockets service on Http4s and two small web applications, and says its concepts translate to Kafka, RabbitMQ or other brokers.[52] Practical Event Sourcing with Scala takes event sourcing out of its enterprise framing, deliberately avoiding domain-driven design and CQRS vocabulary, and builds a question-and-answer web application on Play, Akka Streams, Kafka and Neo4J with a React front end and a time-travel dashboard that rewinds the event log; its sample is mostly environment setup on JDK 8.[25] Event Sourcing in Scala does the modern version in Scala 3 and ZIO: events as sealed families, state as a pure fold over history, commands as a decide function, an append-only PostgreSQL store and projection workers walked in reading order.[53] Saga Architecture in Scala implements one order-placement flow twice, as orchestration with an explicit saga step type and as choreography with events and reactions, with compensating actions for partial failure.[54]

Effects are the hinge on which these systems turn. Effect Oriented Programming makes retries, timeouts, fallbacks and resource finalisation the first thing a reader sees of ZIO, then covers dependency injection, testing, shared state and resilience patterns such as circuit breaking.[48] Pure functional HTTP APIs in Scala measures the pure and impure versions of one service against each other with tests and benchmarks.[47] Sockets and Pipes adds STM, chunked streaming and ExceptT errors to its hand-built server,[7] and The Simple Haskell Handbook reaches STM, agents and webhooks in its CI server.[8] On the BEAM, Building Conduit shows the event-sourced version of a web application with its read model and integration tests.[58]

Sources

Every source is a Leanpub book. 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.
    An Outsider's Guide to Statically Typed Functional Programming, Brian Marick Free sample: the introduction, on why static functional programming is worth learning, the outsider's stance and the plan through Elm and PureScript, and the first functions chapter. 2018. Free sample: PDF · EPUB
  2. 2.
    Thinking with Types, Sandy Maguire: Type-Level Programming in Haskell Free sample: the introduction on who the book is for and the printf example, and the start of chapter 1 on the algebra of types. 2019. Free sample: PDF
  3. 3.
    Happy Learn Haskell Tutorial Volume 1, GetContented Free sample: chapters 1 to 5, from how to learn Haskell enjoyably through values, types, purity and functions that return functions. 2022. Free sample: PDF
  4. 4.
    Book of Monads, Alejandro Serrano Mena Free sample: the full table of contents and the introduction, with its roadmap of the five parts and prerequisites. 2021. Free sample: PDF
  5. 5.
    Finding Success (and Failure) in Haskell, Type Classes: Fall in love with applicative functors Free sample: the table of contents and the preface on why halting at the first failure is not enough, ending before the first code chapter. 2020. Free sample: PDF
  6. 6.
    Production Haskell, Matt Parsons: Succeeding in Industry with Haskell Free sample: the changelog, the introduction and the principles chapter on complexity and novelty budgets. 2023. Free sample: PDF · EPUB
  7. 7.
    Sockets and Pipes, Type Classes: Connect with Haskell Free sample: the contents, the preface with its themes and prerequisites, and the setup chapter. 2023. Free sample: PDF
  8. 8.
    The Simple Haskell Handbook, Marco Sampellegrini: Learn how to build Haskell applications. Free sample: the domain model with non-empty lists, the build state machine and the start of the Docker chapter. 2021. Free sample: PDF
  9. 9.
    Haskell (almost) Standard Libraries, Alejandro Serrano Mena Free sample: the contents, the summary mapping tasks to packages, and the start of the introduction. 2022. Free sample: PDF
  10. 10.
    Optics By Example, Chris Penner: Functional lenses in Haskell Free sample: chapter 2 on what optics are and their strengths and weaknesses, and the start of chapter 3 on lenses; most other sections are placeholders. 2020. Free sample: PDF · EPUB
  11. 11.
    Functional Design and Architecture (Early Edition, 2020), Alexander Granin: Building real programs in static functional languages: application architectures, design patterns, best practices and approaches Free sample: chapter 1 on what software design is and the plan of the book's two projects. 2020, an early edition its author has since reworked. Free sample: PDF · EPUB
  12. 12.
    Algebra-Driven Design, Sandy Maguire: Elegant Solutions from Simple Building Blocks Free sample: the full table of contents and the John Hughes foreword, ending before the author's own chapters. 2023. Free sample: PDF
  13. 13.
    Pragmatic Type-Level Design, Alexander Granin: Practical introduction to type-level programming: design principles, design patterns, methodologies, approaches Free sample: the author's foreword and the opening of chapter 1 on emergent type-level design. 2025. Free sample: PDF · EPUB
  14. 14.
    Functional-Light JavaScript, Kyle Simpson: Balanced, Pragmatic FP in JavaScript Free sample: the preface and chapter 4 on composing functions. 2018. Free sample: PDF · EPUB
  15. 15.
    Unwrapping Monads & Friends, Kyle Simpson: Shining Light on Functional Programming's Scariest Concepts Free sample: the introduction and chapter 2 on what a monad is, with the Identity monad and the laws in JavaScript. 2025. Free sample: PDF · EPUB
  16. 16.
    Functional Programming in Javascript, dimitris papadimitriou: gain an advanced understanding of the mathematics behind functional programming Free sample: the purpose and coding conventions and the first chapter on functors; the sample is a 2020 version. 2025. Free sample: PDF
  17. 17.
    Functional Programming in TypeScript, dimitris papadimitriou: With categories Free sample: the purpose, the note on libraries, and the first chapters on lenses, monoids and the start of algebraic data types; the sample is a 2020 version. 2025. Free sample: PDF
  18. 18.
    Thinking Functionally in PHP, Larry Garfield Free sample: the preface, the introduction comparing paradigms, and the start of Part One on pure functions. 2021. Free sample: PDF · EPUB
  19. 19.
    Java Backend Coding Technology, Sergiy Yevtushenko: Less art, more engineering Free sample: chapter 1 on code unification, the five evaluation criteria and the foundational concepts. 2026. Free sample: PDF · EPUB
  20. 20.
    Functional programming in Modern Java, Jitin Kayyala Free sample: chapter 1 on why Java developers struggle with complexity; later chapters are not in the sample. 2026. Free sample: PDF · EPUB
  21. 21.
    Asynchronous functional javascript, dimitris papadimitriou Free sample: the contents, the purpose and the opening sections on concurrency and the event loop, in a visibly unfinished draft. 2025. Free sample: PDF
  22. 22.
    The Neophyte's Guide to Scala, Daniel Westheide Free sample: the chapter on extractors and pattern matching. 2019, from articles of 2012 and 2013. Free sample: PDF · EPUB
  23. 23.
    Mastering Advanced Scala, Denis Kalinin: Exploring the deep end of functional programming Free sample: the preface and the chapter on implicits, type erasure and type classes, with the start of the ScalaZ chapter. 2020. Free sample: PDF · EPUB
  24. 24.
    Modern Web Development with Scala, Denis Kalinin: A concise step-by-step guide to the Scala ecosystem Free sample: the preface on Scala's adoption and the setup and language-fundamentals chapters. 2020. Free sample: PDF · EPUB
  25. 25.
    Practical Event Sourcing with Scala, Denis Kalinin: A comprehensive example based on Scala, Play and Akka Streams Free sample: the preface on event sourcing and chapter 1 on setting up the project. 2021. Free sample: PDF · EPUB
  26. 26.
    An Elm Primer for React Developers, Christian Ekrem: The Best Way to Learn Real Functional Programming Free sample: the introduction with its first Elm Hook and part of chapter 1 on constraints and costs. 2026. Free sample: PDF · EPUB
  27. 27.
    Clojure Polymorphism, Paul Stadig Free sample: the introduction, the data-transformation example solved three ways, and the analysis and principles. 2016. Free sample: PDF · EPUB
  28. 28.
    Elements of Clojure, Zachary Tellman Free sample: the introduction on tacit knowledge and the first part of the Names chapter. 2019. Free sample: PDF · EPUB
  29. 29.
    Extending and Using Specter, Brian Marick: Get Going Good Free sample: the preface on why Specter, how to use the book, and the first exercises building select. 2016. Free sample: PDF · EPUB
  30. 30.
    The Science of Functional Programming, Sergei Winitzki: A tutorial, with examples in Scala Free sample: the front matter, the preface describing the book's scope and counts, and the contents of chapters 1 to 5. 2025. Free sample: PDF
  31. 31.
    Programming in System Fω using Dhall, Sergei Winitzki Free sample: the front matter, the preface summary and the contents of chapters 1 to 8; no chapter prose. 2026. Free sample: PDF
  32. 32.
    Modern Java: Second Edition, Adam L. Davis: Java 21 and the Java Ecosystem Free sample: Part I on Java's history, syntax and the features of Java 5 to 7. 2025. Free sample: PDF · EPUB
  33. 33.
    Functional Programming for the Object-Oriented Programmer, Brian Marick Free sample: the introduction with the plan of the book, the version history, and the start of chapter 1 on installing Clojure. 2015. Free sample: PDF · EPUB
  34. 34.
    A Go Developer's Notebook, Eleanor McHugh: Where I Go During My Holidays Free sample: the preface and the start of the introduction; no functional programming content is in it. 2019. Free sample: PDF · EPUB
  35. 35.
    Lenses for the Mere Mortal: PureScript Edition, Brian Marick Free sample: the introduction on what optics are for and the first chapter on tuples and records. 2018. Free sample: PDF · EPUB
  36. 36.
    Practical FP in Scala, Gabriel Volpe: A hands-on approach Free sample: the front matter and the table of contents only. 2021. Free sample: PDF
  37. 37.
    Functional Programming Made Easier, Charles Scalfani: A Step-by-Step Guide Free sample: the table of contents only; the article relies on the description. 2021. Free sample: PDF
  38. 38.
    Certainty by Construction, Sandy Maguire: Software and Mathematics in Agda Free sample: the front matter and the detailed table of contents only. 2024. Free sample: PDF
  39. 39.
    The Haskell Blueprint, Gautier DI FOLCO: A Direct Guide to Writing Maintainable, Real-World Software Free sample: the title page and the detailed table of contents only. 2026. Free sample: PDF
  40. 40.
    The Art of Functional Programming, Minh Quang Tran, PhD Free sample: the title page naming OCaml, Haskell and Java; the rest of the sample is unreadable, so the article relies on the description. 2025. Free sample: PDF
  41. 41.
    Phoenix Product Codex, Isaak Tsalicoglou: Develop and deploy a REST API for Product Data Management with Elixir and Phoenix Free sample: the version notice, the chapter-by-chapter summary and the software versions; the chapters themselves are placeholders. 2025. Free sample: PDF · EPUB
  42. 42.
    PureScript by Example, Phil Freeman: Functional Programming for the Web No sample: from the description and table of contents. 2017.
  43. 43.
    JavaScript Allongé, the "Six" Edition, Reg “raganwald” Braithwaite: Programming from Functions to Classes in ECMAScript 2015 No sample: from the table of contents; the description is reader testimonials. 2019.
  44. 44.
    Functional Programming for Mortals, Sam Halliday: with Scalaz No sample: from the description and table of contents. 2026.
  45. 45.
    Essential F#, Ian Russell No sample: from the description and table of contents. 2023.
  46. 46.
    Composing Software, Eric Elliott: An Exploration of Functional Programming and Object Composition in JavaScript No sample: from the description and table of contents. 2024.
  47. 47.
    Pure functional HTTP APIs in Scala, Jens Grassel No sample: from the description and table of contents. 2022.
  48. 48.
    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.
  49. 49.
    Foundations of Clojure, Rakhim Davletkaliyev No sample: from the description and table of contents. 2026.
  50. 50.
    Multi-Paradigm Programming, Marty Yoo: Combining Functional, Object-Oriented, and Lisp Paradigms for Software Design and Implementation No sample: from the description and table of contents. 2025.
  51. 51.
    Scalapedia, Piotr Pruchniewicz: Encyclopedia of the Scala programming language No sample: from the description. 2026.
  52. 52.
    Functional Event-Driven Architecture, Gabriel Volpe: Powered by Scala 3 No sample: from the description and table of contents. 2023.
  53. 53.
    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.
  54. 54.
    Saga Architecture in Scala, Piotr Pruchniewicz: Functional Saga Architecture in Scala 3 and ZIO No sample: from the description and table of contents. 2026.
  55. 55.
    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.
  56. 56.
    Modern Software Design in Fortran, Matthias Noback No sample: from the description and table of contents. 2026.
  57. 57.
    Toy Robot - The Elixir Version, Ryan Bigg No sample: from the description and table of contents. 2024.
  58. 58.
    Building Conduit, Ben Smith: Applying CQRS/ES to an Elixir and Phoenix web app No sample: from the description and table of contents. 2019.

Further reading

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

  • Java Challengers, Rafael Chinelato del Nero: Master the Java Fundamentals with fun Java Code Challenges! Become a Java Challenger! More than seventy Java coding challenges from the basics to streams, modules and concurrency. 2025.
  • Elegant Design Principles, Narayanan Jayaratchagan: Foundations of Software Design Mastery A catalogue of ninety-five software design principles, with functional programming as one thread. 2025.
  • Plutus: Writing reliable smart contracts, Lars Brünjes, Polina Vinogradova, Alejandro Garcia Fdz: NOTICE: This book is out of date. It shows PLUTUS as it was in 2019. We are currently working in the new edition that depicts the latest development of the PLUTUS programming language. Smart contracts on Cardano in the Haskell-based Plutus, out of date by its authors' own notice. 2019.
  • Practical Artificial Intelligence With Scala, Mark Watson: Practical AI Code in Scala Classical AI, neural networks and LLM clients built in Scala 3, one scala-cli project per chapter. 2026.
  • Scala for Apache Spark, Prashant Mhatre Just enough Scala to start Apache Spark programming, from 2017.
  • Thinking in Redux, Nir Kaufman Redux as a frontend messaging system of actions, middleware and reducers. 2018.
  • Web Development from Beginner to Paid Professional, Volume 3, Bolakale Aremu: Learn JavaScript Algorithms & Data Structures Step By Step. Examples, Practice Exercises and Projects Included. Beginner JavaScript exercises with one chapter on functional programming, volume 3 of a web development series. 2026. Free sample: PDF · EPUB
  • 10 More Days to Become a Better Developer, Daniel Scheufler Ten daily practice exercises for developers, one of them a kata across three paradigms. 2025.
  • Ash Framework for Phoenix Developers, Kamaro Lambert: How to write Less code, Ship faster, and extend forever web application using Ash and Phoenix Framework The Ash framework for Phoenix developers, through to writing and publishing an extension. 2026.
  • Native Mobile Apps With Elixir, Kamaro Lambert: From Your First Screen to Production Withou Leaving the Beam Native mobile apps with the BEAM on the phone, an expense app from first screen to release. 2026.

This is an article created from the free samples of 41 Leanpub books and the descriptions and tables of contents of 17 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: 131 books · 6 courses in the Functional Programming category · also filed under Haskell, Clojure, Elixir, Erlang, Scala

All topics