Slide 65
Slide 65 text
Adopt Functional Thinking
● Develop a thinking pattern for why FP in your current code
○ Why currying, monadic, lambda ....
● Global variable is evil
● Small function is easy to be understood
● Rely on the standard lib.
○ operator, Itertools and functools
65
>>> ss = ["Hsinchu", "PyHug", "2018"]
>>> reduce(lambda acc, s: acc + len(s), ss, 0)
16
>>> s s= ["Hsinchu", "PyHug", "2018"]
>>> reduce(lambda l,r: l+r, map(lambda s: len(s), ss))
16
>>> ss = ["Hsinchu", "PyHug", "2018"]
>>> reduce(operator.add, map(len, ss))
16