- Courses
- đ»Programming Languages
- đPython
- Functional Programming
- Currying
On this page
Currying in Python: A Functional Programming Guide
Published on July 6, 2026
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
Currying is a fundamental functional programming technique that transforms a function taking multiple arguments into a sequence of functions, each taking a single argument. Where a standard function expects all its arguments at once, a curried function accepts them one at a time: calling it with the first argument returns a new function that expects the second, and so on, until all arguments are provided and the final result is computed. While Python is not a purely functional language and does not have built-in currying, the concept remains valuable for writing modular, reusable, and composable code. Combined with Python's functools.partial for partial application, currying enables powerful patterns like function factories, data pipelines, and dependency injection â all while keeping code clean and maintainable. This lesson explores currying in depth, distinguishing it from partial application, demonstrating practical implementations, and showing when and why to use this technique in Python.
What Is Currying?â
Currying is the technique of transforming a function that takes multiple arguments into a sequence of functions, each taking a single argument. In mathematical notation, if you have a function f(x, y), its curried form is a function g(x) that returns a function h(y), where h(y) returns the result of f(x, y).
Consider a simple multiplication function:
def multiply(a, b, c):
return a * b * c
This function takes three arguments at once. Its curried version looks like this:
def curried_multiply(a):
def step2(b):
def step3(c):
return a * b * c
return step3
return step2
# Usage
result = curried_multiply(2)(3)(4) # 24
Each call returns a new function that captures the previously provided arguments through closures. The process continues until all arguments are supplied, at which point the final computation occurs.
The Mathematical Rootsâ
The name "currying" honours the logician Haskell Brooks Curry, who made extensive use of this technique. The concept was actually introduced earlier by Moses Schönfinkel â hence the alternative name "Schönfinkelisation" â but Curry's name became the commonly used term. The theoretical roots go back further to the work of Gottlob Frege in the late 19th century.
Currying vs. Partial Applicationâ
A common point of confusion is the distinction between currying and partial application. While related, they are different concepts.
Partial application is the process of fixing a number of arguments to a function, producing another function of smaller arity. It does not change the function's structure â it simply preâfills some arguments and leaves the rest to be supplied later.
from functools import partial
def multiply(a, b, c):
return a * b * c
# Partial application: fix the first argument
multiply_by_2 = partial(multiply, 2)
# multiply_by_2 now expects two arguments: b and c
result = multiply_by_2(3, 4) # 24
Currying, in contrast, transforms the function itself into a chain of unary (singleâargument) functions. A curried function is designed from the start to be called with one argument at a time.
The key difference is that partial application creates a new function by fixing some arguments, while currying restructures the function so that each argument is taken separately. In practice, currying implies that the function can be partially applied at any stage, but not every partially applied function is curried.
Implementing Currying in Pythonâ
Python does not provide builtâin currying, but it can be implemented in several ways.
1. Manual Currying with Nested Functionsâ
The most straightforward approach uses nested functions to capture arguments progressively:
def curry_multiply(a):
def curry_step2(b):
def curry_step3(c):
return a * b * c
return curry_step3
return curry_step2
# Usage
curry_multiply(2)(3)(4) # 24
This approach is explicit but becomes verbose for functions with many arguments.
2. A GeneralâPurpose curry Functionâ
A more flexible implementation uses a recursive approach that works with any number of arguments:
def curry(func):
def curried(*args):
if len(args) >= func.__code__.co_argcount:
return func(*args)
return lambda *more: curried(*(args + more))
return curried
@curry
def multiply(a, b, c):
return a * b * c
# Usage
multiply(2)(3)(4) # 24
multiply(2, 3)(4) # 24
multiply(2)(3, 4) # 24
The curry decorator checks how many arguments the original function expects. If it receives enough arguments, it calls the function directly. Otherwise, it returns a new function that captures the provided arguments and waits for more.
3. Using functools.partial for CurryingâLike Behaviourâ
While functools.partial implements partial application rather than true currying, it can be used to achieve similar results and is often more practical in Python:
from functools import partial
def multiply(a, b, c):
return a * b * c
# Sequential partial application
step1 = partial(multiply, 2) # fixes a=2
step2 = partial(step1, 3) # fixes b=3
result = step2(4) # supplies c=4
The partial function is a builtâin tool from the functools module. It is efficient, wellâtested, and familiar to most Python developers. For practical purposes, partial often serves the same role as currying without requiring custom implementations.
4. Using ThirdâParty Librariesâ
Several libraries provide currying functionality:
returnsâ offers a typed@currydecorator for currying functionsfuncyâ providescurry(func, n)for currying functions with optional arity specificationpytyped-curryâ a functional tool for currying with static type support
from returns.curry import curry
@curry
def multiply(a, b, c):
return a * b * c
multiply(2)(3)(4) # 24
These libraries can reduce boilerplate and provide additional features like type safety.
Practical Examplesâ
1. Creating Specialised Functionsâ
Currying makes it easy to create specialised versions of generalâpurpose functions:
def multiply(a, b):
return a * b
# Curried form
def curried_multiply(a):
def with_b(b):
return a * b
return with_b
# Create specialised functions
double = curried_multiply(2)
triple = curried_multiply(3)
print(double(5)) # 10
print(triple(5)) # 15
This pattern reduces code duplication and makes intent explicit.
2. Building Data Processing Pipelinesâ
Currying is foundational for function composition and building data processing pipelines:
def compose(f, g):
return lambda x: f(g(x))
def curried_compose(f):
def with_g(g):
return lambda x: f(g(x))
return with_g
# Functions to compose
def add_one(x):
return x + 1
def double(x):
return x * 2
# Compose: double â add_one
composed = curried_compose(double)(add_one)
print(composed(3)) # double(add_one(3)) -> double(4) -> 8
Currying allows functions to be combined flexibly, enabling pipelines that are both readable and reusable.
3. Unit Conversion with Function Compositionâ
Currying enables clean function composition for unit conversion:
def compose(b, c, d):
def a(x):
return b(c(d(x)))
return a
def km_to_m(dist):
return dist * 1000
def m_to_cm(dist):
return dist * 100
def cm_to_ft(dist):
return dist / 30.48
transform = compose(cm_to_ft, m_to_cm, km_to_m)
print(transform(565)) # 1853674.5406824148
Each conversion function is simple and focused. Composition chains them together without modifying the original functions.
4. Currying HigherâOrder Functionsâ
Currying can be applied to higherâorder functions like map, filter, and reduce:
def curry_map(func):
def mapped(iterable):
return map(func, iterable)
return mapped
def square(x):
return x * x
# Curried map with square function
square_map = curry_map(square)
result = list(square_map([1, 2, 3, 4, 5]))
# [1, 4, 9, 16, 25]
This pattern makes higherâorder functions more modular and reusable.
5. BMI Calculator with Curryingâ
A practical example: a Body Mass Index calculator:
def BMI(weight, height):
return weight / height ** 2
def bmi_curried(height):
def bmi_weight(weight):
return BMI(weight, height)
return bmi_weight
# Create a function for a specific height
bmi_for_1_76 = bmi_curried(1.76)
bmi = bmi_for_1_76(72) # 23.243801652892564
The curried version separates the fixed height from the variable weight, making the function more reusable.
Benefits of Curryingâ
Modularity and Reusabilityâ
Currying breaks complex functions into simpler, singleâargument components. Each component can be reused independently, reducing duplication and improving maintainability.
Function Compositionâ
Currying is foundational for function composition â combining simple functions to build more complex ones. This is a core technique in functional programming pipelines.
Lazy Evaluationâ
Currying supports lazy evaluation by allowing arguments to be supplied incrementally. Computation can be delayed until all arguments are provided, which can improve performance in certain scenarios.
Improved Readabilityâ
When used appropriately, currying can make code more readable by making the flow of data explicit. The stepâbyâstep application of arguments mirrors the logical progression of the computation.
Common Pitfalls and How to Avoid Themâ
1. Confusing Currying with Partial Applicationâ
Remember that currying transforms the function structure; partial application creates a new function from an existing one without changing its structure. Using the terms interchangeably can lead to confusion.
2. Overusing Curryingâ
Currying is not always the right tool. For simple functions, the overhead of nested functions can make code less readable. Use currying when it genuinely improves modularity or enables composition, not as a stylistic affectation.
3. Performance Overheadâ
Currying introduces function call overhead. In performanceâcritical code, the cost of nested function calls may be significant. Consider whether the benefits of currying outweigh the performance cost.
4. Type Hints and Curryingâ
Currying with nested functions can complicate type hints. Libraries like returns provide typed currying, but if you are using manual currying, be mindful of type annotations.
Summaryâ
Currying is a powerful functional programming technique that transforms multiâargument functions into sequences of singleâargument functions. While Python does not have builtâin currying, it can be implemented manually or using libraries. The related concept of partial application, provided by functools.partial, is more commonly used in Python and often serves a similar purpose.
Currying offers several benefits: it promotes modularity, enables function composition, supports lazy evaluation, and can improve code readability. However, it also introduces overhead and can make code harder to understand if overused. The key is to apply currying judiciously â when it genuinely simplifies code, enables reuse, or facilitates composition in a functional pipeline.
By understanding currying and its relationship to partial application, you gain another valuable tool for writing clean, modular, and expressive Python code in the functional programming style.
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Closures
Next
Lazy Evaluation
-
What Is Currying?
- The Mathematical Roots
-
Currying vs. Partial Application
-
Implementing Currying in Python
- 1. Manual Currying with Nested Functions
- 2. A GeneralâPurpose
curryFunction - 3. Using
functools.partialfor CurryingâLike Behaviour - 4. Using ThirdâParty Libraries
-
Practical Examples
- 1. Creating Specialised Functions
- 2. Building Data Processing Pipelines
- 3. Unit Conversion with Function Composition
- 4. Currying HigherâOrder Functions
- 5. BMI Calculator with Currying
-
Benefits of Currying
- Modularity and Reusability
- Function Composition
- Lazy Evaluation
- Improved Readability
-
Common Pitfalls and How to Avoid Them
- 1. Confusing Currying with Partial Application
- 2. Overusing Currying
- 3. Performance Overhead
- 4. Type Hints and Currying
-
Summary
