re: Introduction to functional programming with Python examples VIEW POST


Would be nice to have something like the Maybe-Monad in the functools package for example. Sometimes python's None is a valid output and can not be used equivalently to Nothing.

What I like to do is to break down my problem into only functions and then build up objects from them. This way I can reduce the tests around the object and easier test the functions.

Constructive feedback:

  • I think you could have added, that map and filter return you a genrator. You wrap them in your examples in list( ... ) and get the same result as in the list comprehensions.

  • A cool thing to use is the operator module. Then you can do something like this:

from operator import add, mul
from functools import reduce
print(reduce(add, [1,2,3,4]))
# => 10
print(reduce(mul, [1,2,3,4]))
# => 24

This reduces the amount of simple lambda functions like lambda x, y: x + y and makes the code more readable.

  • Cleanly written, I really like that 👍
code of conduct - report abuse