Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Functional Programming with C++

You're reading from   Hands-On Functional Programming with C++ An effective guide to writing accelerated functional code using C++17 and C++20

Arrow left icon
Product type Paperback
Published in Jun 2019
Publisher Packt
ISBN-13 9781789807332
Length 358 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Alexandru Bolboaca Alexandru Bolboaca
Author Profile Icon Alexandru Bolboaca
Alexandru Bolboaca
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Section 1: Functional Building Blocks in C++ FREE CHAPTER
2. An Introduction to Functional Programming 3. Understanding Pure Functions 4. Deep Dive into Lambdas 5. The Idea of Functional Composition 6. Partial Application and Currying 7. Section 2: Design with Functions
8. Thinking in Functions - from Data in to Data out 9. Removing Duplication with Functional Operations 10. Improving Cohesion Using Classes 11. Test-Driven Development for Functional Programming 12. Section 3: Reaping the Benefits of Functional Programming
13. Performance Optimization 14. Property-Based Testing 15. Refactoring to and through Pure Functions 16. Immutability and Architecture - Event Sourcing 17. Section 4: The Present and Future of Functional Programming in C++
18. Lazy Evaluation Using the Ranges Library 19. STL Support and Proposals 20. Standard Language Support and Proposals 21. Assessments 22. Other Books You May Enjoy

To get the most out of this book

This book assumes a good knowledge of the C++ syntax and of basic STL containers. However, it does not assume any knowledge of functional programming, functional constructs, category theory, or math. We've gone to great lengths to ensure that each concept is explained clearly and from a practical, programmer-centric perspective.

We strongly encourage you to play around with the code after reading the chapters or try to replicate the code from the samples after finishing a chapter. Even better, pick a coding kata (for example, from http://codingdojo.org/kata/) problem and try to solve it using the techniques from this book. You will learn much more by combining reading with toying with code than by simply reading the theory on its own.

Most of the content in this book requires you to think differently about the code structure and, sometimes, this will be contrary to what you are used to. However, we see functional programming as another tool in your toolkit; it doesn't contradict what you already know, instead, it just provides you with additional instruments to use with your production code. When and how you use them is your decision.

To run the code samples from the book, you will need g++ and the make command. Alternatively, you can run the samples using any compiler that supports C++ 17, but you will need to manually run each file. All the code samples compile and automatically run with make or make [specific example], and provide the output on the console with a few caveats that follow.

The memory optimization samples from Chapter 10, Performance Optimization, need to run with make allMemoryLogs or a specific target, require a keyboard press after each target run, and will create log files in the out/ folder, showing the evolution of allocated memory for the process. This will only work on Linux systems.

The reactive programming sample from Chapter 10, Performance Optimization and requires user input. Just input numbers and the program will compute in a reactive way whether they are prime or not. The program should receive inputs even while computing. The code samples from Chapter 16, Standard Language Support and Proposals, require a compiler that supports C++20; at this point, g++-8 is used. You will need to install g++-8 separately.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Hands-On-Functional-Programming-with-Cpp. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Code in Action

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "In STL, it's implemented with the find_if function. Let's see it in action."

A block of code is set as follows:

class Number{
public:
static int zero(){ return 0; }
static int increment(const int value){ return value + 1; }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

First call: 1,367 ns < 16,281 ns
Second call: 58,045 ns < 890,056 ns
Third call: 16,167 ns > 939 ns
Fourth call: 1,334 ns > 798 ns
Warnings or important notes appear like this.
Tips and tricks appear like this.
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image