גamla is a performant functional programming library for python which supports async.
Installation
pip install gamla
Debugging anonymous compositions
gamla.compose(x, y, z) produces a new function which doesn't have a proper name. If x raises an exception, it is sometimes hard to figure out where this occurred. To overcome this, set the env variable GAMLA_DEBUG_MODE (to anything) to get more useful exceptions. This is turned on only by flag because it incurs significant overhead so things might get slow.
Mixing asynchronous and synchronous code
Most functions in this lib will work seamlessly with async and regular functions, and allow the developer to focus on the logic instead of deciding where to place an await.
For example:
import asyncio
import gamla
def increment(i):
return i + 1
async def increment_async(i):
asyncio.sleep(1)
return i + 1
async def run():
mixed_composition = gamla.compose_left(increment, increment_async, increment)
return await mixed_composition(0) # returns 3!
Migrating from toolz
The main problems - toolz is slow and does not support async functions.
Why is it slow?
It uses the expensive inspect module to look at a function’s arguments, and doing so at each run. This happens not only on curried functions, but in compositions as well.
Why does gamla not suffer from this problem?
Two reasons:
- It does no longer support binary signatures on things like
map, so it doesn’t need to infer anything (these are higher order functions ingamla). - The
gamla.curryfunction pays for the signature inspection in advance, and remembers its results.
Function mapping and common gotchas (written in blood):
curried.(filter|map|valmap|itemmap|keymap)->gamla.$1(make sure the call is with a single argument)toolz.identity->gamla.identitytoolz.contains->gamla.containstoolz.lt->gamla.greater_thantoolz.gt->gamla.less_thantoolz.ge->gamla.less_equalstoolz.le->gamla.greater_equalstoolz.filter(None) -> gamla.filter(gamla.identity)toolz.excepts(a, b, c)->gamla.excepts(a, c, b)toolz.excepts(a, b)->gamla.excepts(a, gamla.just(None), b)(following the “data-last” currying convention)
Releasing a new version
- Create a pypi account.
- Download twine and give it your pypi credentials.
- Get pypi permissions for the project from its owner.
python setup.py sdist bdist_wheel; twine upload dist/*; rm -rf dist;
Release files for gamla 50
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gamla-50.tar.gz | 23.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gamla-50-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 299.7 kB
Release files / gamla-50.tar.gz
| Download URL | gamla-50.tar.gz |
|---|---|
| Size | 23.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
34f1779c256d5b87abb2c154975d59f478413c41175d8f7134c3121b5cb43551
|
|
BLAKE2b-256 checksum How to use checksums |
845ee6649565151cd2c2c54e68be704cd3bd1591acf7fdd73afed689020446ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.2
|
Release files / gamla-50-py3-none-any.whl
| Download URL | gamla-50-py3-none-any.whl |
|---|---|
| Size | 276.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51d22d7406a46780f54069b1a1783c881003a191461d70d90fb4c705af524cab
|
|
BLAKE2b-256 checksum How to use checksums |
e58fb5fece2dfe403730b5540a7c0a338a8c9a7bd94f8ddaeeed35f5064729f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
|