Functional Programming in C++
320 pages
English
PDF
4.5

Functional Programming in C++

Functional Programming in C++

Author:

Year:

Summary:

Introduction

The book «Functional Programming in C++» (2018) by Ivan Čukić is not just another textbook on the language, but a deep dive into the paradigm of functional programming (FP) in the context of modern C++. While most books on C++ focus on the object-oriented or procedural approach, Čukić offers a different perspective on the language: as a powerful tool for writing clean, predictable, and easily testable code using FP ideas. The book is aimed at practicing developers already familiar with the basics of C++ and aims to show how functional concepts can improve everyday work.

What is this book about?

The book consists of 15 chapters divided into four parts. The first part lays the foundation: it explains what functional programming is, why it is useful in C++, and introduces key concepts — pure functions, immutability, absence of side effects. The second part is devoted to practical tools: lambda expressions, higher-order functions, function composition, currying, and partial application. The third part is the most advanced: the author introduces the concept of monads (specifically Maybe, Either, IO), functors, and applicative functors, showing how to implement them in C++ and use them for error handling and working with side effects. The fourth part contains examples of real projects: parsers, generators, parallel computing, as well as tips for integrating a functional style into existing codebases.

Who is this book for?

The book is intended for intermediate and advanced C++ developers who want to expand their paradigm arsenal and learn to write more reliable and maintainable code. It will also be useful for programmers familiar with functional languages (Haskell, Scala) who want to bring these concepts to C++. Beginners in C++ may find the book challenging due to the abundance of template metaprogramming and advanced topics.

What will the reader learn?

  • Basics of FP in C++: pure functions, immutability, referential transparency.
  • Lambda expressions and closures: syntax, variable capture, generic lambdas (C++14).
  • Higher-order functions: std::function, std::bind, custom implementations of map, filter, fold.
  • Function composition: creating chains of data transformations.
  • Monads and functors: implementing Maybe, Either, State, IO in C++.
  • Error handling without exceptions: using std::optional, std::expected (analogous to Either).
  • Lazy evaluation and generators: creating infinite sequences.
  • Parallelism and concurrency: a functional approach to multithreading.
  • Integration with OOP: how to combine functional and object-oriented patterns.

Strengths

The main advantage of the book is its practical focus. Čukić does not just retell FP theory, but shows how to implement each concept using C++ features, taking into account the specifics of the language (memory management, templates, operator overloading). The example code is neat, well-commented, and uses C++14/17 features. The author pays attention to performance: he explains when a functional style can lead to overhead and how to avoid it. Another plus is the gradual increase in complexity: from simple lambdas to monads, allowing the reader to smoothly dive into the topic. The book contains many exercises and self-test questions.

Who is it recommended for

We recommend the book to everyone who wants to go beyond the usual OOP and master the functional approach in C++. It will be useful for developers of high-load systems, financial applications, game engines, and any software where code reliability and predictability are important. If you already use

Recommendations