Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
Functional Python Programming

You're reading from   Functional Python Programming Discover the power of functional programming, generator functions, lazy evaluation, the built-in itertools library, and monads

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher Packt
ISBN-13 9781788627061
Length 408 pages
Edition 2nd Edition
Languages
Arrow right icon
Toc

Table of Contents (18) Chapters Close

Preface 1. Understanding Functional Programming 2. Introducing Essential Functional Concepts FREE CHAPTER 3. Functions, Iterators, and Generators 4. Working with Collections 5. Higher-Order Functions 6. Recursions and Reductions 7. Additional Tuple Techniques 8. The Itertools Module 9. More Itertools Techniques 10. The Functools Module 11. Decorator Design Techniques 12. The Multiprocessing and Threading Modules 13. Conditional Expressions and the Operator Module 14. The PyMonad Library 15. A Functional Approach to Web Services 16. Optimizations and Improvements 17. Other Books You May Enjoy

What this book covers

Chapter 1, Understanding Functional Programming, introduces some of the techniques that characterize functional programming. We’ll identify some of the ways to map those features to Python. Finally, we’ll also address some ways that the benefits of functional programming accrue when we use these design patterns to build Python applications.

Chapter 2, Introducing Essential Functional Concepts, delves into six central features of the functional programming paradigm. We’ll look at each in some detail to see how they’re implemented in Python. We’ll also point out some features of functional languages that don’t apply well to Python. In particular, many functional languages have complex type-matching rules required to support compiling and optimizing.

Chapter 3, Functions, Iterators, and Generators, will show how to leverage immutable Python objects, and generator expressions adapt functional programming concepts to the Python language. We’ll look at some of the built-in Python collections and how we can leverage them without departing too far from functional programming concepts.

Chapter 4, Working with Collections, shows how you can use a number of built-in Python functions to operate on collections of data. This chapter will focus on a number of relatively simple functions, such as any() and all(), which will reduce a collection of values to a single result.

Chapter 5, Higher-Order Functions, examines the commonly-used higher-order functions such as map() and filter(). It also shows a number of other functions that are also higher-order functions as well as how we can create our own higher-order functions.

Chapter 6, Recursions and Reductions, teaches how to design an algorithm using recursion and then optimize it into a high-performance for loop. We’ll also look at some other reductions that are widely used, including collections.Counter().

Chapter 7, Additional Tuple Techniques, showcases a number of ways that we can use immutable tuples (and namedtuples) instead of stateful objects. Immutable objects have a much simpler interface—we never have to worry about abusing an attribute and setting an object into some inconsistent or invalid state.

Chapter 8, The Itertools Module, examines a number of functions in this standard library module. This collection of functions simplifies writing programs that deal with collections or generator functions.

Chapter 9, More Itertools Techniques, covers the combinatoric functions in the itertools module. These functions are somewhat less useful. This chapter includes some examples that illustrate ill-considered use of these functions and the consequences of combinatoric explosion.

Chapter 10, The Functools Module, focuses on how to use some of the functions in this module for functional programming. A few functions in this module are more appropriate for building decorators, and they are left for Chapter 11, Decorator Design Techniques. The other functions, however, provide several more ways to design and implement function programs.

Chapter 11, Decorator Design Techniques, looks at how you can look at a decorator as a way to build a composite function. While there is considerable flexibility here, there are also some conceptual limitations: we’ll look at ways that overly-complex decorators can become confusing rather than helpful.

Chapter 12, The Multiprocessing and Threading Modules, points out an important consequence of good functional design: we can distribute the processing workload. Using immutable objects means that we can’t corrupt an object because of poorly-synchronized write operations.

Chapter 13, Conditional Expressions and the Operator Module, lists some ways to break out of Python’s strict order of evaluation. There are limitations to what we can achieve here. We’ll also look at the operator module and how this can lead to slight clarification of some simple kinds of processing.

Chapter 14, The PyMonad Library, examines some of the features of the PyMonad library. This provides some additional functional programming features. It also 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 might get optimized into an undesirable order. Since Python already has strict ordering of f expressions and statements, the monad feature is more instructive than practical.

Chapter 15, A Functional Approach to Web Services, shows how we can think of web services as a nested collection of functions that transform a request into a reply. We’ll see ways to leverage functional programming concepts for building responsive, dynamic web content.

Chapter 16, Optimizations and Improvements, includes some additional tips on performance and optimization. We’ll emphasize techniques such as memoization, because they’re easy to implement and can—in the right context—yield dramatic performance improvements.

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