Currying the hard way

We can create curried functions manually, without using the decorator from the PyMonad library; one way of doing this is shown in the function definition that follows:

def f(x, *args):    def f1(y, *args):        def f2(z):            return (x+y)*z        if args:            return f2(*args)        return f2    if args:        return f1(*args)    return f1

This curries a function, , into a function, f(x), which returns a function. Conceptually, . We then curried the intermediate function to create the f1(y) and f2(z) function, .

When we evaluate the f(x) function, we'll get a new ...

Get Functional Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.