6.4 Summary
In this chapter, we’ve looked at two significant functional programming topics. We’ve looked at recursions in some detail. Many functional programming language compilers will optimize a recursive function to transform a call in the tail of the function to a loop. This is sometimes called tail recursion elimination. More commonly, it’s known as tail-call optimization. In Python, we must do the tail-call optimization manually by using an explicit for
statement, replacing a purely functional recursion.
We’ve also looked at reduction algorithms, including sum()
, count()
, max()
, and min()
functions. We looked at the collections.Counter()
function and related groupby()
reductions.
We’ve also looked at how parsing (and lexical scanning) are similar to reductions since they transform sequences of tokens (or sequences of characters) into higher-order collections with more complex properties. We’ve examined a design pattern that decomposes...