Functional Python Programming - Second Edition

Create succinct and expressive implementations with functional programming in Python
Preview in Mapt

Functional Python Programming - Second Edition

Steven F. Lott
New Release!

Create succinct and expressive implementations with functional programming in Python
Mapt Subscription
FREE
$29.99/m after trial
eBook
$28.00
RRP $39.99
Save 29%
Print + eBook
$49.99
RRP $49.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$28.00
$49.99
$29.99 p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 14 Day Trial

Frequently bought together


Functional Python Programming - Second Edition Book Cover
Functional Python Programming - Second Edition
$ 39.99
$ 28.00
Python: Advanced Predictive Analytics Book Cover
Python: Advanced Predictive Analytics
$ 79.99
$ 56.00
Buy 2 for $35.00
Save $84.98
Add to Cart

Book Details

ISBN 139781788627061
Paperback408 pages

Book Description

If you’re a Python developer who wants to discover how to take the power of functional programming (FP) and bring it into your own programs, then this book is essential for you, even if you know next to nothing about the paradigm.

Starting with a general overview of functional concepts, you’ll explore common functional features such as first-class and higher-order functions, pure functions, and more. You’ll see how these are accomplished in Python 3.6 to give you the core foundations you’ll build upon. After that, you’ll discover common functional optimizations for Python to help your apps reach even higher speeds.

You’ll learn FP concepts such as lazy evaluation using Python’s generator functions and expressions. Moving forward, you’ll learn to design and implement decorators to create composite functions. You'll also explore data preparation techniques and data exploration in depth, and see how the Python standard library fits the functional programming model. Finally, to top off your journey into the world of functional Python, you’ll at look at the PyMonad project and some larger examples to put everything into perspective.

Table of Contents

Chapter 1: Understanding Functional Programming
Identifying a paradigm
Subdividing the procedural paradigm
A classic example of functional programming
Exploratory data analysis
Summary
Chapter 2: Introducing Essential Functional Concepts
First-class functions
Immutable data
Strict and non-strict evaluation
Recursion instead of an explicit loop state
Functional type systems
Familiar territory
Learning some advanced concepts
Summary
Chapter 3: Functions, Iterators, and Generators
Writing pure functions
Functions as first-class objects
Using strings
Using tuples and named tuples
Cleaning raw data with generator functions
Using lists, dicts, and sets
Summary
Chapter 4: Working with Collections
An overview of function varieties
Working with iterables
Using zip() to structure and flatten sequences
Using reversed() to change the order
Using enumerate() to include a sequence number
Summary
Chapter 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
Review of some design patterns
Summary
Chapter 6: Recursions and Reductions
Simple numerical recursions
Group-by reduction from many items to fewer
Summary
Chapter 7: Additional Tuple Techniques
Using tuples to collect data
Using named tuples to collect data
Building named tuples with functional constructors
Avoiding stateful classes by using families of tuples
Polymorphism and type-pattern matching
Summary
Chapter 8: The Itertools Module
Working with the infinite iterators
Using the finite iterators
Cloning iterators with tee()
The itertools recipes
Summary
Chapter 9: More Itertools Techniques
Enumerating the Cartesian product
Reducing a product
Permuting a collection of values
Generating all combinations
Recipes
Summary
Chapter 10: The Functools Module
Function tools
Memoizing previous results with lru_cache
Defining classes with total ordering
Applying partial arguments with partial()
Reducing sets of data with the reduce() function
Summary
Chapter 11: Decorator Design Techniques
Decorators as higher-order functions
Cross-cutting concerns
Composite design
Adding a parameter to a decorator
Implementing more complex decorators
Complex design considerations
Summary
Chapter 12: The Multiprocessing and Threading Modules
Functional programming and concurrency
What concurrency really means
Using multiprocessing pools and tasks
Using a multiprocessing pool for concurrent processing
Summary
Chapter 13: Conditional Expressions and the Operator Module
Evaluating conditional expressions
Using the operator module instead of lambdas
Starmapping with operators
Reducing with operator module functions
Summary
Chapter 14: The PyMonad Library
Downloading and installing
Functional composition and currying
Functional composition and the PyMonad * operator
Functors and applicative functors
Monad bind() function and the >> operator
Implementing simulation with monads
Additional PyMonad features
Summary
Chapter 15: A Functional Approach to Web Services
The HTTP request-response model
The WSGI standard
Defining web services as functions
Tracking usage
Summary
Chapter 16: Optimizations and Improvements
Memoization and caching
Specializing memoization
Tail recursion optimizations
Optimizing storage
Optimizing accuracy
Case study–making a chi-squared decision
Computing expected values and displaying a contingency table
Functional programming design patterns
Summary

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 features to ensure efficient functional programs
  • Use Python strings with object-oriented suffix notation and prefix notation
  • Avoid stateful classes with families of tuples
  • Design and implement decorators to create composite functions
  • Use functions such as max(), min(), map(), filter(), and sorted()
  • Write higher-order functions

Authors

Table of Contents

Chapter 1: Understanding Functional Programming
Identifying a paradigm
Subdividing the procedural paradigm
A classic example of functional programming
Exploratory data analysis
Summary
Chapter 2: Introducing Essential Functional Concepts
First-class functions
Immutable data
Strict and non-strict evaluation
Recursion instead of an explicit loop state
Functional type systems
Familiar territory
Learning some advanced concepts
Summary
Chapter 3: Functions, Iterators, and Generators
Writing pure functions
Functions as first-class objects
Using strings
Using tuples and named tuples
Cleaning raw data with generator functions
Using lists, dicts, and sets
Summary
Chapter 4: Working with Collections
An overview of function varieties
Working with iterables
Using zip() to structure and flatten sequences
Using reversed() to change the order
Using enumerate() to include a sequence number
Summary
Chapter 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
Review of some design patterns
Summary
Chapter 6: Recursions and Reductions
Simple numerical recursions
Group-by reduction from many items to fewer
Summary
Chapter 7: Additional Tuple Techniques
Using tuples to collect data
Using named tuples to collect data
Building named tuples with functional constructors
Avoiding stateful classes by using families of tuples
Polymorphism and type-pattern matching
Summary
Chapter 8: The Itertools Module
Working with the infinite iterators
Using the finite iterators
Cloning iterators with tee()
The itertools recipes
Summary
Chapter 9: More Itertools Techniques
Enumerating the Cartesian product
Reducing a product
Permuting a collection of values
Generating all combinations
Recipes
Summary
Chapter 10: The Functools Module
Function tools
Memoizing previous results with lru_cache
Defining classes with total ordering
Applying partial arguments with partial()
Reducing sets of data with the reduce() function
Summary
Chapter 11: Decorator Design Techniques
Decorators as higher-order functions
Cross-cutting concerns
Composite design
Adding a parameter to a decorator
Implementing more complex decorators
Complex design considerations
Summary
Chapter 12: The Multiprocessing and Threading Modules
Functional programming and concurrency
What concurrency really means
Using multiprocessing pools and tasks
Using a multiprocessing pool for concurrent processing
Summary
Chapter 13: Conditional Expressions and the Operator Module
Evaluating conditional expressions
Using the operator module instead of lambdas
Starmapping with operators
Reducing with operator module functions
Summary
Chapter 14: The PyMonad Library
Downloading and installing
Functional composition and currying
Functional composition and the PyMonad * operator
Functors and applicative functors
Monad bind() function and the >> operator
Implementing simulation with monads
Additional PyMonad features
Summary
Chapter 15: A Functional Approach to Web Services
The HTTP request-response model
The WSGI standard
Defining web services as functions
Tracking usage
Summary
Chapter 16: Optimizations and Improvements
Memoization and caching
Specializing memoization
Tail recursion optimizations
Optimizing storage
Optimizing accuracy
Case study–making a chi-squared decision
Computing expected values and displaying a contingency table
Functional programming design patterns
Summary

Book Details

ISBN 139781788627061
Paperback408 pages
Read More

Read More Reviews

Recommended for You

Python: Advanced Predictive Analytics Book Cover
Python: Advanced Predictive Analytics
$ 79.99
$ 56.00
Wireshark Revealed: Essential Skills for IT Professionals Book Cover
Wireshark Revealed: Essential Skills for IT Professionals
$ 79.99
$ 56.00
Understanding Software Book Cover
Understanding Software
$ 23.99
$ 16.80
Matplotlib for Python Developers - Second Edition Book Cover
Matplotlib for Python Developers - Second Edition
$ 31.99
$ 22.40
Game Programming using Qt 5 Beginner's Guide - Second Edition Book Cover
Game Programming using Qt 5 Beginner's Guide - Second Edition
$ 39.99
$ 28.00
Mastering pfSense - Second Edition Book Cover
Mastering pfSense - Second Edition
$ 39.99
$ 28.00