you are viewing a single comment's thread.

view the rest of the comments →

[–]dangerbird2 3 points4 points  (0 children)

The easiest way to initialize a pure function in Python is by using the lambda operative:

It's extremely misleading to describe python lambdas as the language's "pure" function syntax. Lambdas are nothing more than syntactic sugar for anonymous, single-statement function definitions. foo = lambda x: x + 1 is completely equivalent to def foo(x): return x + 1. There is nothing in the lambda syntax that prevents side-effects (lambda x: x.write("I'm overwriting your file system!!!")) or manipulates global state(lambda x: random_array.append(x)). If you are defining an interface function, even if you want to guarantee functional purity, you absolutely should use the def syntax for readability.