Functional Python Programming

(Wang) #1

The PyMonad Library


Summary


In this chapter, we looked at how we can use the PyMonad library to express some
functional programming concepts directly in Python. The module shows many
important functional programming techniques.


We looked at the idea of currying, a function that allows combinations of arguments
to be applied to create new functions. Currying a function also allows us to use
functional composition to create more complex functions from simpler pieces.
We looked at functors that wrap simple data objects to make them into functions
which can also be used with functional composition.


Monads are a way to impose a strict evaluation order when working with an
optimizing compiler and lazy evaluation rules. In Python, we don't have a good use
case for monads, because Python is an imperative programming language under the
hood. In some cases, imperative Python may be more expressive and succinct than a
monad construction.


In the next chapter, we'll look at how we can apply functional programming
techniques to build web services applications. The idea of HTTP could be
summarized as response = httpd(request). Ideally, HTTP is stateless, making it
a perfect match for functional design. However, most web sites will maintain state,
using cookies to track session state.

Free download pdf