Functional Programming in C++: A Modern Approach
300 pages
English
PDF
4.5

Functional Programming in C++: A Modern Approach

Functional Programming in C++: A Modern Approach

Author:

Year:

Summary:

The book "Functional Programming in C++" is a practical guide for developers who want to go beyond the traditional imperative approach and master functional paradigms in the context of modern C++ (C++17/20 standards). The author shows how to harness the power of the language — from lambda expressions and templates to STL containers — to create more predictable, testable, and concise code.



What this book is about

  • FP Basics in C++: pure functions, data immutability, absence of side effects. How these principles improve readability and debugging.
  • Lambda expressions and closures: from simple anonymous functions to complex closures with variable capture. Examples for STL algorithms.
  • Function composition and currying: creating call chains using std::function and custom combinators. Implementing data processing pipelines.
  • Monads and functors in C++: Maybe, Either, and State patterns with templates. Error handling without exceptions.
  • Lazy evaluation and infinite sequences: range generation, memoization, deferred loading using std::generator (C++23) and custom iterators.
  • Concurrency and the functional approach: using std::async, std::future, and functional pipelines for safe multithreading.


Who this book is for

  • Experienced C++ developers wanting to write cleaner and more modular code.
  • Programmers familiar with functional languages (Haskell, Scala) but working in C++.
  • Students and engineers studying modern programming paradigms.


What you will learn

  • How to replace loops and mutations with data transformations using std::transform, std::accumulate, and custom algorithms.
  • How to design APIs using composition instead of inheritance.
  • How to test functions in isolation, independent of global state.
  • How to implement the "Strategy" and "Command" patterns using functional objects.


The book contains numerous code examples, exercises, and practical tasks. You will learn to combine functional and imperative techniques, choosing the optimal approach for each task. After reading, you will be able to write C++ code that is easier to maintain, extend, and debug.



This edition is suitable both for self-study and for use as a reference on functional techniques in C++.

Recommendations