0%

Book Description

Python is not a functional programming language, but it is a multi-paradigm language that makes functional programming easy to perform, and easy to mix with other programming styles. In this paper, David Mertz, a director of Python Software Foundation, examines the functional aspects of the language and points out which options work well and which ones you should generally decline.

Mertz describes ways to avoid Python’s imperative-style flow control, the nuances of callable functions, how to work lazily with iterators, and the use of higher-order functions. He also lists several third-party Python libraries useful for functional programming.

Topics include:

  • Using encapsulation and other means to describe "what" a data collection consists of, rather than "how" to construct a data collection
  • Creating callables with named functions, lambdas, closures, methods of classes, and multiple dispatch
  • Using Python’s iterator protocol to accomplish the same effect as a lazy data structure
  • Creating higher-order functions that take functions as arguments and/or produce a function as a result

Table of Contents

  1. Preface
    1. What Is Functional Programming?
    2. Beyond the Standard Library
    3. Resources
    4. A Stylistic Note
  2. 1. (Avoiding) Flow Control
    1. Encapsulation
    2. Comprehensions
      1. Generators
      2. Dicts and Sets
    3. Recursion
    4. Eliminating Loops
      1. Eliminating Recursion
  3. 2. Callables
    1. Named Functions and Lambdas
    2. Closures and Callable Instances
    3. Methods of Classes
      1. Accessors and Operators
      2. Static Methods of Instances
      3. Generator Functions
    4. Multiple Dispatch
      1. Many Branches
      2. Delegating to the Object
      3. Pattern Matching
      4. Predicate-Based Dispatch
  4. 3. Lazy Evaluation
    1. The Iterator Protocol
    2. Module: itertools
      1. Chaining Iterables
  5. 4. Higher-Order Functions
    1. Utility Higher-Order Functions
    2. The operator Module
    3. The functools Module
    4. Decorators
18.118.24.30