> Markdown version of [/videos/1409-functional-programming-in-c](https://www.wearedevelopers.com/videos/1409-functional-programming-in-c). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Functional Programming in C++ Eliminate mutable state without sacrificing execution speed. Discover how C++20 ranges and monadic error handling merge functional programming safety with hardware-native performance. - **Speakers:** [Jonathan Müller](https://www.wearedevelopers.com/@jonathan-muller) - **Event:** World Congress 2025 - **Published:** August 20, 2025 - **Duration:** 26:54 - **URL:** https://www.wearedevelopers.com/videos/1409-functional-programming-in-c ## Summary Functional programming aims to eliminate mutable state and the bugs that come with it—such as race conditions and broken invariants—but purely functional languages often struggle to map efficiently to imperative hardware. C++ provides a pragmatic middle ground: developers can write optimized, low-level building blocks and compose them using functional paradigms. This hybrid approach delivers the safety and clarity of functional composition alongside the hardware-native performance of modern C++. A major application of this paradigm is algorithmic composition using C++20 ranges and views. Instead of relying on manual `for` loops and eager container allocations, developers can build declarative pipelines using lazily evaluated tools like `transform`, `filter`, and `chunk_by`. This lazy composition minimizes temporary memory overhead and keeps intermediate states entirely declarative. Furthermore, because the execution details abstract away the control flow, complex data transformations become trivial to parallelize—often requiring just a single line change using C++26 parallel algorithms. This functional approach extends naturally to error handling and asynchronous operations by treating them as composable values rather than control-flow jumps. Utilizing `std::expected`, developers can build robust pipelines where `transform` handles success cases and `and_then` cleanly chains subsequent fallible operations, avoiding deeply nested logic while making every potential failure point perfectly transparent. Ultimately, these constructs—ranges, `std::expected`, and the upcoming C++26 Senders/Receivers—share the same underlying mathematical structure: monads. By demystifying monads as simple "boxes of some value that can be transformed while keeping it inside the box," developers can uniformly apply declarative composition across data parsing, explicit error propagation, and parallel I/O. **Keywords:** c++ functional programming, c++20 ranges and views, std::expected error handling, lazy evaluation pipelines, declarative data composition, c++26 parallel algorithms, eliminating mutable state, senders and receivers framework, monadic composition in c++, functional error propagation, lazily evaluated data transformations, c++ algorithm composition ## Chapters 1. **Introduction to functional programming concepts in C++** (00:11) — Adopting declarative programming paradigms eliminates state mutations and simplifies reasoning in C++ code. 1. **Filtering and transforming ranges with lazy evaluation views** (02:47) — Replacing eager intermediate containers with C++20 views enables efficient and stateless lazy evaluation. 1. **Finding pair sums using Cartesian products and parallel algorithms** (06:57) — Defining combinations with lazy Cartesian products allows seamless optimization through standard parallel algorithms. 1. **Applying chunking patterns to identify continuous subsequences lazily** (09:47) — Using chunk boundaries based on predicates simplifies the extraction of subranges without manual state tracking. 1. **Reversing string words with conditional range pipelines and subsets** (11:49) — Combining splitting and conditional reverse operations cleanly transforms strings without eager memory allocations. 1. **Summarizing range composition patterns and standard library algorithms** (14:06) — Applying standard views minimizes manual loops when manipulating collections and data streams. 1. **Handling errors functionally using expected values and pipeline continuations** (15:01) — Modeling failures as concrete return values prevents unpredictable control flow paths caused by exceptions. 1. **Separating I/O and concurrency from computation using execution actions** (21:14) — Defining I/O operations as deferred action lists eliminates side effects and simplifies software testing. 1. **Simplifying monads as composable value boxes within C++** (24:53) — Treating ranges, expected types, and I/O objects as monads unifies their composition through common transform operations. ## Related Moments - [Functional programming principles and practical application in C#](https://www.wearedevelopers.com/videos/569-down-the-oregon-trail-with-functional-c) (from "Down the Oregon Trail with Functional C#") - [Defining the core principles of functional programming](https://www.wearedevelopers.com/videos/408-a-guide-to-functional-programming) (from "A Guide To Functional Programming") - [Building scalable applications with reactive programming](https://www.wearedevelopers.com/videos/383-kubernetes-native-java) (from "Kubernetes Native Java") - [Using higher-order functions to manipulate data collections](https://www.wearedevelopers.com/videos/229-using-backend-languages-for-frontends-why-clojurescript-is-an-awesome-idea) (from "Using backend languages for frontends: Why ClojureScript is an awesome idea!") - [Benefits of writing encapsulated functional code](https://www.wearedevelopers.com/videos/408-a-guide-to-functional-programming) (from "A Guide To Functional Programming") - [Functional programming roots and security focus](https://www.wearedevelopers.com/videos/237-developer-s-perspective-overview-of-the-tezos-blockchain-ecosystem) (from "Developer’s Perspective: Overview of the Tezos Blockchain Ecosystem") ## Related Articles - [4 reasons why you should learn Rust in 2021 – and maybe even have fun doing it](https://www.wearedevelopers.com/magazine/35-4-reasons-why-you-should-learn-rust-in-2021-and-maybe-even-have-fun-doing-it) - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Building AI Solutions with Rust and Docker](https://www.wearedevelopers.com/magazine/494-building-ai-solutions-with-rust-and-docker) - [Dev Digest 138 - Are you secure about this?](https://www.wearedevelopers.com/magazine/486-dev-digest-138-are-you-secure-about-this) ## Related Jobs - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Senior Software Engineer, Client Apps Platform](https://www.wearedevelopers.com/jobs/ext/1773893-senior-software-engineer-client-apps-platform) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub** - [Cloud Foundations Team](https://www.wearedevelopers.com/jobs/ext/1483289-cloud-foundations-team) at **GitHub** - [Principal Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1465908-principal-software-engineer-database-infrastructure) at **GitHub** - [Senior Software Engineer,Billing](https://www.wearedevelopers.com/jobs/ext/1991843-senior-software-engineer-billing) at **GitHub**