What this book covers
Chapter 1, Introducing Functional Programming, introduces some of the techniquesthat characterize functional programming. We'll identify some of the ways to mapthese features to Python, and finally, we'll also address some ways that the benefitsof functional programming accrue when we use these design patterns to buildPython applications.
Chapter 2, Introducing Some Functional Features, will delve into six central featuresof the functional programming paradigm. We'll look at each in some detail tosee how they're implemented in Python. We'll also point out some features offunctional languages that don't apply well to Python. In particular, many functionallanguages have complex type-matching rules required to support compilationand optimization.
Chapter 3, Functions, Iterators, and Generators, will show how to leverage immutablePython objects and generator expressions, and adapt functional programmingconcepts to the Python language. We'll look at some of the built-in Pythoncollection and how we can leverage them without departing too far fromfunctional programming concepts.
Chapter 4, Working with Collections, shows how we can use a number of built-inPython functions to operate on collections of data. This section will focus on anumber of relatively simple functions such as any() and all(), which willreduce a collection of values to a single result.
Chapter 5, Higher-order Functions, examines the commonly used higher orderfunctions such as map() and filter(). The chapter also includes a number of otherfunctions that are also higher-order functions, as well as how we can create our ownhigher-order functions.
Chapter 6, Recursions and Reductions, shows how we can design an algorithm usingrecursion and then optimize it into a high performance for loop. We'll also look atsome other reductions that are widely used, including the collections.Counter()function.
Chapter 7, Additional Tuple Techniques, shows a number of ways in which we can useimmutable tuples and namedtuples instead of stateful objects. Immutable objectshave a much simpler interface: we never have to worry about abusing an attributeand setting an object into some inconsistent or invalid state.
Chapter 8, The Itertools Module, examines a number of functions in the standardlibrary module. This collection of functions simplifies writing programs that dealwith collections or generator functions.
Chapter 9, More Itertools Techniques, covers the combinatoric functions in the itertoolsmodule. These functions are somewhat less useful. This chapter includes someexamples that illustrate ill-considered uses of these functions and the consequencesof combinatoric explosion.
Chapter 10, The Functools Module, will show how to use some of the functions inthis module for functional programming. A few of the functions in this moduleare more appropriate for building decorators, and are left for the next chapter.The other functions, however, provide several more ways to design andimplement function programs.
Chapter 11, Decorator Design Techniques, shows how we can look at a decorator asa way to build a composite function. While there is considerable flexibility here,there are also some conceptual limitations: we'll look at ways in which overlycomplex decorators can become confusing rather than helpful.
Chapter 12, The Multiprocessing and Threading Modules, points out an importantconsequence of good functional design: we can distribute the processing workload.Using immutable objects means that we can't corrupt an object because of poorlysynchronized write operations.
Chapter 13, Conditional Expressions and the Operator Module, will show some ways inwhich we can break out of Python's strict order of evaluation. There are limitations towhat we can achieve here. We'll also look at the operator module and how the operatormodule can lead to some slight clarification of some simple kinds of processing.
Chapter 14, The PyMonad Library, examines some of the features of the PyMonadlibrary. This provides some additional functional programming features. Thisalso provides a way to learn more about monads. In some functional languages,monads are an important way to force a particular order for operations that mightget optimized into an undesirable order. Since Python already has strict ordering ofexpressions and statements, the monad feature is more instructive than practical.
Chapter 15, A Functional Approach to Web Services, shows how we can think of webservices as a nested collection of functions that transform a request into a reply.We'll see ways in which we can leverage functional programming concepts forbuilding responsive, dynamic web content.Chapter 16, Optimizations and Improvements, includes some additional tips onperformance and optimization. We'll emphasize techniques like memoizationbecause they're easy to implement and can—in the right context—yield dramaticperformance improvements.