Libraries Supporting Composition

Learn to compose curried functions using the * operator in PyMonad.

Existing libraries supporting composition

There are quite a few open-source libraries that provide functional programming support, including a compose function.

funcy and are two such libraries that can be found on or installed with pip.


We will concentrate on PyMonad in this section. It provides composition of curried functions (see the PyMonad @curry decorator described earlier in this chapter).

Rather than using a compose function, PyMonad uses a compose operator, *.

Here is how it works.

Example one

Assume that our task is to create an iterator that counts down. We start by creating curried versions of the built-in reversed and range functions as shown below, from line 3 to line 9. Once these functions are defined, composing them is quite neat (line 11).

Get hands-on with 1200+ tech skills courses.