Currying
-
a function of the form can always be written as , , or
-
this is called currying or partial application
times = lambda a, b : a * b
double = partial(times, 2)
- why bother? the
square_and_sum
is still too complicated
square_and_sum = lambda lst : reduce(tally, map(square1, filter(evenQ, lst)))
- instead, let’s over do things significantly
filterEven = partial(filter, evenQ)
squareEach = partial(map, square1)
tallyAll = partial(reduce, tally)
square_and_sum = compose(tallyAll, squareEach, filterEven)
-
please, don't do this in python ... ever!
-
use Haskell instead