λ Functional Python
Pure Functions & Immutability
Write code that's easy to test and reason about.
A *pure* function returns the same output for the same input and has no side effects — no mutating globals, no printing, no I/O.
# Impure: mutates the argument
def add_impure(xs, x):
xs.append(x)
return xs
# Pure: returns a new list
def add_pure(xs, x):
return [*xs, x]
Pure functions compose freely and parallelize safely.