Book description
Create succinct and expressive implementations with functional programming in Python
In Detail
Python is an easy-to-learn and extensible programming language that offers a number of functional programming features. It's ideally suited to a number of applications in the broad space of data science.
This practical guide demonstrates the Python implementation of a number of functional programming techniques and design patterns. Starting with a general overview of functional programming concepts, you will explore common functional features such as first-class and higher-order functions, pure functions and more, and how these are accomplished in Python. Additionally, you will cover how common functional optimizations can be handled in Python. You'll also explore data preparation techniques and data exploration in depth. Moving on, you will learn how the Python standard library fits the functional programming model. The book concludes with a look at the PyMonad project and some larger examples.
By the end of this book, you will be able to understand what functional programming is all about, its impact on the programming workflow, why it's important, and how to implement it in Python.
What You Will Learn
- Use Python's generator functions and generator expressions to work with collections in a non-strict (or lazy) manner
- Utilize Python library modules including itertools, functools, multiprocessing, and concurrent.futures for efficient functional programs
- Use Python strings using object-oriented suffix notation and prefix notation
- Avoid stateful classes with families of tuples
- Design and implement decorators to create composite functions
- Use functions like max(), min(), map(), filter(), and sorted()
- Write higher-order functions
Table of contents
-
Functional Python Programming
- Table of Contents
- Functional Python Programming
- Credits
- About the Author
- About the Reviewers
- www.PacktPub.com
- Preface
- 1. Introducing Functional Programming
- 2. Introducing Some Functional Features
- 3. Functions, Iterators, and Generators
- 4. Working with Collections
-
5. Higher-order Functions
- Using max() and min() to find extrema
- Using Python lambda forms
- Lambdas and the lambda calculus
- Using the map() function to apply a function to a collection
- Using map() with multiple sequences
- Using the filter() function to pass or reject data
- Using filter() to identify outliers
- The iter() function with a sentinel value
- Using sorted() to put data in order
- Writing higher-order functions
- Writing higher-order mappings and filters
- Writing generator functions
- Building higher-order functions with Callables
- Looking at some of the design patterns
- Summary
- 6. Recursions and Reductions
- 7. Additional Tuple Techniques
-
8. The Itertools Module
- Working with the infinite iterators
-
Using the finite iterators
- Assigning numbers with enumerate()
- Running totals with accumulate()
- Combining iterators with chain()
- Partitioning an iterator with groupby()
- Merging iterables with zip_longest() and zip()
- Filtering with compress()
- Picking subsets with islice()
- Stateful filtering with dropwhile() and takewhile()
- Two approaches to filtering with filterfalse() and filter()
- Applying a function to data via starmap() and map()
- Cloning iterators with tee()
- The itertools recipes
- Summary
- 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
- Downloading and installing
- Functional composition and currying
- Functional composition and the PyMonad multiplication operator
- Functors and applicative functors
- Monad concepts, the bind() function and the Binary Right Shift operator
- Implementing simulation with monads
- Additional PyMonad features
- Summary
- 15. A Functional Approach to Web Services
- 16. Optimizations and Improvements
- Index
Product information
- Title: Functional Python Programming
- Author(s):
- Release date: January 2015
- Publisher(s): Packt Publishing
- ISBN: 9781784396992
You might also like
book
Functional Python Programming - Second Edition
Create succinct and expressive implementations with functional programming in Python About This Book Learn how to …
book
Functional Python Programming - Third Edition
“Using this book has propelled my efficiency in solving leetcode challenges.” - Discord user, zizu Python …
book
Functional Programming in Python
Python is not a functional programming language, but it is a multi-paradigm language that makes functional …
book
Advanced Python Programming
Create distributed applications with clever design patterns to solve complex problems Key Features Set up and …