Little λ supports a functional-like syntax for function composition by
extending the @
operator used for linear function composition to
nonlinear functions.
To use, simply put a little λ
at the start of the functions
you want to compose separated by composition operators @
:
n_unique = λ @ len @ set
n_unique([1, 1, 4, 5])
# returns 3
The λ
can also be used to generate simple lambda functions from
most binary operations, which can themselves be composed:
is_even = (λ == 0) @ (λ % 2)
Note that the term (λ == 0)
counts as a λ
at the start of the
composition.
Finally, Little λ
can be used for partial application via λ(fn, *args, **kwargs)
.
This makes it particularly easy to use λ
with higher-order functions:
sum_of_squares = λ @ sum @ λ(map, λ ** 2)
Here, λ(map, λ ** 2)
is the map function, partially applied with the square function.
Little λ makes your functional Python code look the part!
sum_of_even_squares = λ @ sum @ λ(map, λ ** 2) @ λ(filter, (λ == 0) @ (λ % 2))