Jump to ratings and reviews
Rate this book

Functional Python Programming: Discover the power of functional programming, generator functions, lazy evaluation, the built-in itertools library, and monads, 2nd Edition

Rate this book

Create succinct and expressive implementations with functional programming in Python

Key Features Learn how to choose between imperative and functional approaches based on expressiveness, clarity, and performance Get familiar with complex concepts such as monads, concurrency, and immutability Apply functional Python to common Exploratory Data Analysis (EDA) programming problems Book Description

If you’re a Python developer who wants to discover how to take the power of functional programming (FP) and bring it into your own programs, then this book is essential for you, even if you know next to nothing about the paradigm.

Starting with a general overview of functional concepts, you’ll explore common functional features such as first-class and higher-order functions, pure functions, and more. You’ll see how these are accomplished in Python 3.6 to give you the core foundations you’ll build upon. After that, you’ll discover common functional optimizations for Python to help your apps reach even higher speeds.

You’ll learn FP concepts such as lazy evaluation using Python’s generator functions and expressions. Moving forward, you’ll learn to design and implement decorators to create composite functions. You'll also explore data preparation techniques and data exploration in depth, and see how the Python standard library fits the functional programming model. Finally, to top off your journey into the world of functional Python, you’ll at look at the PyMonad project and some larger examples to put everything into perspective.

What you will learn Use Python's generator functions and generator expressions to work with collections in a non-strict (or lazy) manner Utilize Python library modules including itertools, functools, multiprocessing, and concurrent features to ensure efficient functional programs Use Python strings with object-oriented suffix notation and prefix notation Avoid stateful classes with families of tuples Design and implement decorators to create composite functions Use functions such as max(), min(), map(), filter(), and sorted() Write higher-order functions Who this book is for

This book is for Python developers who would like to perform Functional programming with Python. Python Programming knowledge is assumed.

Table of Contents Understanding Functional Programming Introducing essential functional concepts Functions, Iterators and Generators Working with Collections Higher-Order Functions Recursions and Reductions Additional tuple techiques The Itertools Module More Itertools Techniques The Functools Module Decorator Design Techniques The Multiprocessing and Threading Modules The Operator Module The PyMonad Library A Functional Approach to Web Services Optimizations and Improvements

410 pages, Kindle Edition

First published January 31, 2015

33 people are currently reading
97 people want to read

About the author

Steven F. Lott

18 books6 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
9 (19%)
4 stars
15 (32%)
3 stars
17 (36%)
2 stars
3 (6%)
1 star
2 (4%)
Displaying 1 - 12 of 12 reviews
Profile Image for Julio Biason.
199 reviews28 followers
August 27, 2020
Another book the proves my theory that the quality of a book is inversely proportional to the amount of "as follows".

But functional programming in Python is generators.

That's it: Generators. Oh, generators and tuples.

There is a lot in this book, but mostly seems... wrong. For example, talking about "tail call optimization", when Python does not have them. And then talking how to optimize those -- which, again, it is plain "replace with a generator".

Also, the case for tuples is that namedtuples is mentioned, but rarely used. This makes code hard to read, except the author decided to create lambdas to extract them, so you end up with a bunch of xy_g = lambda p: p[0][1][0]. What the fuck is 0, 1 and 0 again in this? Why not use name tuples and, instead of this atrocity, go with p.position.x?

Other examples of wrong things:

- "extract the docstring function": Doctstrings are strings, not functions.
- "GNU Image Manipulation Program (GIMP) GNU General Public License (GPL) file format": Neither GIMP not GPL is a file format; one is a photo editor and the other is a license.
- "This is relatively simple implementation copied from the World Wide Web": And we all know how things on the web are reliant.
- "We can use ((line.split() for line in file) to create a sequence of ten tuples": First of all, yes, the there is some unbalanced parenthesis there; second, that thing won't generate ten tuples, it will generate as many as the lines in the file -- which is never shown, by the way.
- Calling functions that return generators "higher-order functions". And no, the function does not receive a function, it simply returns a generator.
- "perms = permutations(range(6)))))". Yup, there are 4 extra closing parenthesis.
- Splitting a string with a path in it by /, then checking the first value instead of, say, path.startswith('expected_value').
- "We've created a Counter() function": Counter is a class, not a function.
- Lots of "not clear if this is helpful". Ok, showing some sort of code is ok, but not explaining where if it is useful -- or if it is useful at all -- is plain... lazy.
- "We've shown the loop here to clarify that the server must, generally, be crashed": It's the first time that I see that we expect a server to be crashed.
- There is a convoluted aggregation grouping things in a dictionary with a key and a count, and then using Counter() to check the number of times something appear. Problem is, when Counter() process the dict, it will get only the keys, so the whole process of generating the dictionary is completely useless.
- By the end of the book, I'm not sure if things are being double double-quoted (as in ""this is string"") or quadruple single-quote (''''this is string'''') -- but neither format is valid Python.

Besides all that, there is a bunch of explanations that are very much akin to


a = a + 1

Adds 1 to a.


Also, there are chapters for multiprocessing, which has absolutely nothing functional about it and WSGI, which, again, has nothing functional about it.

The whole book feels rushed and badly reviewed -- if reviewed before publishing at all.
Profile Image for Rui Carmo.
10 reviews65 followers
January 3, 2016
I was one of the reviewers for this book prior to publishing, and found it to be a well thought out, comprehensive approach to functional programming. The only point where it fell short (to around a half star) was that it could be a bit longer, something I'm positive will be fixed in another edition :)
Profile Image for Illia.
210 reviews4 followers
September 5, 2016
Cпочатку дуже цікаво, але, десь починаючи с 13-14 глави, автора кудись почало заносити і стало вже нуднувато.
13 reviews
September 6, 2021
I haven't finished reading it (though, I don't need to). I might use it as a reference, but I am a bit disappointed by the example with generators, which seemed to be broken when I tested it. I think a book is supposed to provide details in a simple manner. That's when you can trust the source you are reading. There are many details in the book which I needed to skip. There are things which I would have liked to be discussed, like semaphores, mutex, locks, rlock, conditions, events and the differences for each of them and when to use one over the other and things like that.
Profile Image for Strong Extraordinary Dreams.
592 reviews27 followers
June 5, 2017
Well, this is a book about functional programming in Python.

Seems to be quite focused, lots of stuff about functional programming and how to do it in python. No good as any sort of general text book, though.
Profile Image for Tony Poerio.
212 reviews13 followers
June 25, 2017
Intro-level coverage of functional programming concepts, and lots of Python examples.

I learned some cool tips & tricks with Python syntax. Wasn't too dense, and felt easy to follow. The author does a good job of both explaining and pacing.

Worth a read for anyone interested in FP and Python.
Profile Image for Jin Shusong.
78 reviews1 follower
May 4, 2018
This book is not very easy for beginners. But the author really explained the techniques in functional programming. Those who read the book throughly definitely will learn some useful things from the author. I plan to read it again in two weeks.
Profile Image for Bing Wang.
33 reviews6 followers
March 21, 2018
not very systematic book. More like a introduction about "how to use XXX ..". Still good to help you build a notion that you could do it in functional way in python if you remember XXX
Profile Image for John.
113 reviews26 followers
November 10, 2019
Good exposure to Python's functional tools. What I didn't like so much was 1. the examples: they were totally number crunching related for no reason. I mean, GPS data crunching as an example? Nothing better could be found? 2. The explanation about functional concepts. Especially monads are described as something totally simple which is not needed in python.
Profile Image for Shashank Sharma.
9 reviews3 followers
June 5, 2015
A good book if you are starting with Functional Programming and Python is the language that you use. The content is good and so is the coverage. I would rate it slightly higher than 4 stars
Displaying 1 - 12 of 12 reviews

Can't find what you're looking for?

Get help and learn more about the design.