Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/packquickly/little_lambda
Function composition, the un-Pythonic way!
https://github.com/packquickly/little_lambda
functional-programming python
Last synced: 21 days ago
JSON representation
Function composition, the un-Pythonic way!
- Host: GitHub
- URL: https://github.com/packquickly/little_lambda
- Owner: packquickly
- License: apache-2.0
- Created: 2023-05-25T04:54:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-09-04T09:30:38.000Z (over 1 year ago)
- Last Synced: 2024-12-12T23:26:44.458Z (about 1 month ago)
- Topics: functional-programming, python
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Little λ
Little λ is a tiny python utility for function composition!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 `@`:```python
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:```python
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:```python
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!
```python
sum_of_even_squares = λ @ sum @ λ(map, λ ** 2) @ λ(filter, (λ == 0) @ (λ % 2))
```WARNING
Little λ is not a maintained package and is not intended for serious use.
It is by design not Pythonic, and it likely has many edge-cases I'm unaware of,
and may not ever fix.