Skip to main content

Functional Programming in Python

functools Deep Dive

0:00
LearnStep 1/3

Advanced Functional Tools

The functools module provides higher-order functions and operations on callable objects. It allows for powerful functional programming patterns in Python.

Memoization with lru_cache

Memoization caches the results of expensive function calls. Python provides decorators for this.

python

Partial Functions

partial freezes some portion of a function's arguments and/or keywords, resulting in a new object with a simplified signature.

python

Ordering Classes

@total_ordering fills in missing ordering methods (__le__, __gt__, etc.) given a class that defines __eq__ and one other comparison method.

python

Single Dispatch

@singledispatch transforms a function into a generic function, which can have different behaviors depending on the type of its first argument.

python