Nice, short little book!<p>`compose` can be simpler:<p><pre><code> def compose(fn, *fns):
def _composer(f, g):
return lambda *args: f(g(*args))
return reduce(_composer, fns, fn)
</code></pre>
This little function is really, really cool because it allows you to build up more interesting functions by piecing together a bunch of small, useful ones.<p><pre><code> def upper(s):
return s.upper()
def exclaim(s):
return s + '!'
# instead of this
really_angry = lambda s: exclaim(exclaim(upper(s)))
really_angry('napster bad') # NAPSTER BAD!!
# we can do this
really_angry = compose(upper, exclaim, exclaim)
really_angry('fire good') # FIRE GOOD!!
# and
import operator as op
from functools import partial as p
max(map(compose(p(op.add, 1), p(op.mul, 3)), (1, 2, 3, 4)))
</code></pre>
`compose` is a neat function and worth exploring. This is a cool book and I always hope Python gets more light shone on its FP-friendly features.