Combining map() and reduce()

We can see how to build higher-order functions around these simple definitions. We'll show a simplistic map-reduce function that combines the map() and reduce() functions as follows:

from typing import Callable, Iterable, Anydef map_reduce(        map_fun: Callable,        reduce_fun: Callable,        source: Iterable) -> Any:    return reduce(reduce_fun, map(map_fun, source))

We've created a composite function from the map() and reduce() functions that take three arguments, the mapping transformation, the reduction operation, and the iterable or sequence source of items to process.

In its most generic form, shown previously, it's difficult to make any more formal assertions about the data types involved. The map and reduce functions ...

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.