Functional programming in Python

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepython
def add(a, b):
... return a + b
...
>>> def double(a):
... return 2 * a
...
>>> compose(double, add)(5, 6)
22

Also note that f • g that sequence f(); g(); is the same as compose(g, f) because that's g(f()), which would call f first.  Weird but correct.

...