Advanced Functional Programming with Elixir
Model Behavior, Manage Complexity, and Maximize Maintainability
by Joseph Koski
Combine advanced functional programming concepts with production-ready
Elixir and proven domain-driven design techniques to write cleaner, more
thoughtful software. You’ll explore foundational ideas like equality,
ordering, predicates, monoids, and monads—then go beyond syntax as you
develop intuition for composing logic, modeling behavior, and growing
systems. With a focus on maintainable, declarative code over theory,
you’ll gain practical, composable patterns you can apply right away.
Get ready to manage crowds, adjust priorities, and keep everyone safe in
FunPark, a place that never sits still. Your job is to model that
complexity and build the systems that keep everything running smoothly,
even as the business team is still figuring out what they want and the
experts keep rewriting the rules.
Using core abstractions—equality, ordering, predicates, monoids, and
monads—you’ll break problems into small, composable pieces that are
both well-behaved and easy to combine. Rather than getting bogged down
in theory or formal proofs, you’ll dive into real-world Elixir—using
protocols, structs, and pattern matching to express shared behavior
across your domain. Along the way, you’ll build the vocabulary and
mental models you need to organize complex logic, supported by a
production-ready open-source library you can use, extend, and explore in
your own projects.
Whether you’re an Elixir developer mastering functional programming or a
functional programmer exploring Elixir, you’ll discover how to write
code that’s easier to reason about—and create systems that stay
understandable, even as they grow.
What You Need
To follow along with the examples in this book, you’ll need Elixir
version ~> 1.16, access to the interactive shell (iex), and a code
editor that supports Elixir syntax—such as Visual Studio Code, Neovim,
or any editor you’re comfortable with. You won’t need Phoenix or any
additional setup; the examples are minimal and self-contained, so you to
focus on functional concepts without configuration overhead. If you’re
unsure how to install Elixir, see the official instructions at
elixir-lang.org.
Resources
Releases:
- B2.0 2025/09/02
- B1.0 2025/08/18
Note: Contents and extracts of beta books will change as the book is developed.
- Introduction
- How This Book Works
- Who This Book Is For
- Online Resources
- Conventions Used In This Book
- Build FunPark: Model Real-World Data
- Define the Ride Model
- Implement Fast Passes for Priority Access
- Model the Patrons
- Speak the Language
- What We’ve Learned
- Implement Domain-Specific Equality with Protocols
- Polymorphic Equality
- Implement Equality for FunPark Contexts
- Equality Is Contextual
excerpt

- Transform Inputs Before Matching
- Harness Equality for Collections
- What We’ve Learned
- Create Flexible Ordering with Protocols
- Define Order with a Protocol
- Implement Order for FunPark Contexts
- Transform Inputs Before Comparison
- Harness Order for Collections
- Reverse the Order
- Reduce Repetitive Code with Macros
- What We’ve Learned
- Combine with Monoids
- Define the Protocol
- Combine Numbers with Sum
- Combine Equality
- Combine Order
- Generalize Maximum
- Manage Complexity
- What We’ve Learned
- Define Logic with Predicates
- Simple Predicates
- Combine Predicates
- Predicates That Span Contexts
excerpt

- Compose Multi-Arity Functions with Curry
- Harness Predicates for Collections
- Model the FastPass
- Fold Conditional Logic
- What We’ve Learned
- Compose in Context with Monads
- Build the Monad
excerpt

- Model Neutrality with Identity
- What We’ve Learned
- Access Shared Environment with Reader
- Build the Structures
- Monad Behaviors
- Avoid Prop Drilling
- Dependency Injection
- Shared Configuration
- What We Learned
- Manage Absence with Maybe
- Build the Structures
- Fold Branches
- Lift Other Contexts
- Bridge Elixir Patterns
- Define Equality
- Establish Order
- Lift Custom Comparisons
- Model Absence in a Monoid
- Implement the Monadic Behaviors
- Refine Lists
- Filter Within Composition
- What We’ve Learned
- Model Outcomes with Either
- Structure of Either
- Validation
- From Bind to Combine
- Make Errors Explicit
- What We’ve Learned
- Coordinate Tasks with Effect
- Build the Effect
- Deferred Transformation
- Effectful Store
- Maintenance Repository
- Inject Behavior, Not Configuration
- Flip the Logic
- What We’ve Learned
- Answers
- Equality Chapter Answers
- Order Chapter Answers
- Monoid Chapter Answers
- Predicate Chapter Answers
Author
Joseph Koski is a software engineer with expertise in functional
programming, domain-driven design, and safety-critical systems. He
created the Funx library, bringing tools like monads to Elixir. He
writes at joekoski.com, sharing insights on
functional programming, real-time systems, and using Elixir to solve
complex, reliability-focused problems.