Skip to Content
Functional Python Programming - Second Edition
book

Functional Python Programming - Second Edition

by Steven F. Lott
April 2018
Intermediate to advanced content levelIntermediate to advanced
408 pages
10h 42m
English
Packt Publishing
Content preview from Functional Python Programming - Second Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Python Programming - Third Edition

Functional Python Programming - Third Edition

Steven F. Lott

Publisher Resources

ISBN: 9781788627061Supplemental Content