"Lazy" calculations support.
Project description
lz
In what follows python
is an alias for python3.5
or pypy3.5
or any later version (python3.6
, pypy3.6
and so on).
Installation
Install the latest pip
& setuptools
packages versions
python -m pip install --upgrade pip setuptools
User
Download and install the latest stable version from PyPI
repository
python -m pip install --upgrade lz
Developer
Download the latest version from GitHub
repository
git clone https://github.com/lycantropos/lz.git
cd lz
Install dependencies
python -m pip install -r requirements.txt
Install
python setup.py install
Usage
lz
provides a bunch of utilities for working with functions, predicates & iterables such as
-
>>> from lz.functional import compose >>> sum_of_first_n_natural_numbers = compose(sum, range) >>> sum_of_first_n_natural_numbers(10) 45
-
>>> from lz.functional import curry >>> curried_power = curry(pow) >>> two_to_power = curried_power(2) >>> two_to_power(10) 1024
-
flipping positional parameters order
>>> from lz.functional import flip >>> flipped_power = flip(pow) >>> flipped_power(2, 4) 16
-
packing function's arguments
>>> from lz.functional import pack >>> packed_int = pack(int) >>> packed_int(['10']) 10 >>> packed_int(['10'], {'base': 2}) 2
-
left partial application
>>> from lz import left >>> count_from_zero_to = left.applier(range, 0) >>> list(count_from_zero_to(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-
right partial application
>>> from lz import right >>> square = right.applier(pow, 2) >>> square(10) 100
-
negating predicate
>>> from lz.logical import negate >>> false_like = negate(bool) >>> false_like([]) True >>> false_like([0]) False
-
conjoining predicates
>>> from lz.logical import conjoin >>> is_valid_constant_identifier = conjoin(str.isupper, str.isidentifier) >>> is_valid_constant_identifier('SECOND_SECTION') True >>> is_valid_constant_identifier('2ND_SECTION') False
-
disjoining predicates
>>> from lz.logical import disjoin >>> alphabetic_or_numeric = disjoin(str.isalpha, str.isnumeric) >>> alphabetic_or_numeric('Hello') True >>> alphabetic_or_numeric('42') True >>> alphabetic_or_numeric('Hello42') False
-
exclusive disjoining predicates
>>> from lz.logical import exclusive_disjoin >>> from keyword import iskeyword >>> valid_object_name = exclusive_disjoin(str.isidentifier, iskeyword) >>> valid_object_name('valid_object_name') True >>> valid_object_name('_') True >>> valid_object_name('1') False >>> valid_object_name('lambda') False
-
reversing sequences and any string streams
>>> from lz.reversal import reverse >>> list(reverse(range(10))) [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] >>> import io >>> list(reverse(io.BytesIO(b'Hello\nWorld!'))) [b'World!', b'Hello\n']
-
chunking iterable
>>> from lz.iterating import chopper >>> to_triplets = chopper(3) >>> list(map(tuple, to_triplets(range(10)))) [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9,)]
-
sliding over iterable
>>> from lz.iterating import slider >>> slide_pairwise = slider(2) >>> list(slide_pairwise(range(10))) [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)]
-
interleaving iterables
>>> from lz.iterating import interleave >>> list(interleave([range(10), range(10, 20)])) [0, 10, 1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6, 16, 7, 17, 8, 18, 9, 19]
-
iterable transposition
>>> from lz.transposition import transpose >>> list(map(tuple, transpose(zip(range(10), range(10, 20))))) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (10, 11, 12, 13, 14, 15, 16, 17, 18, 19)]
-
iterable duplication
>>> from lz.replication import duplicate >>> list(map(tuple, duplicate(range(10)))) [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)]
and many more.
Development
Building docs
Install project in editable mode
python -m pip install -e .
Install dependencies
python -m pip install -r docs/requirements.txt
Build docs
cd docs
make html
Bumping version
Preparation
Install bump2version.
Pre-release
Choose which version number category to bump following semver specification.
Test bumping version
bump2version --dry-run --verbose $CATEGORY
where $CATEGORY
is the target version number category name, possible
values are patch
/minor
/major
.
Bump version
bump2version --verbose $CATEGORY
This will set version to major.minor.patch-alpha
.
Release
Test bumping version
bump2version --dry-run --verbose release
Bump version
bump2version --verbose release
This will set version to major.minor.patch
.
Running tests
Install dependencies
python -m pip install -r requirements-tests.txt
Plain
pytest
Inside Docker
container:
- with
CPython
docker-compose --file docker-compose.cpython.yml up
- with
PyPy
docker-compose --file docker-compose.pypy.yml up
Bash
script (e.g. can be used in Git
hooks):
-
with
CPython
./run-tests.sh
or
./run-tests.sh cpython
-
with
PyPy
./run-tests.sh pypy
PowerShell
script (e.g. can be used in Git
hooks):
- with
CPython
.\run-tests.ps1
or.\run-tests.ps1 cpython
- with
PyPy
.\run-tests.ps1 pypy
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lz-0.11.0.tar.gz
.
File metadata
- Download URL: lz-0.11.0.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.5.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d241ccc5b4f1a4fbbd508460b6ad38491518a3ce4844ccf5247029286eb5ac3e |
|
MD5 | 601715dfd15e4e6e1d27261198b4af7b |
|
BLAKE2b-256 | 64e05965e5cb71ddc1bbe8351118151d421aead33350f110c7c8439eff68bdfd |
Provenance
File details
Details for the file lz-0.11.0-py3-none-any.whl
.
File metadata
- Download URL: lz-0.11.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.5.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f52868fab33fc2ae0620a549da6d51266abc952cd5adfed82b9d794b3d8c469c |
|
MD5 | df30c85599dbc0e0b535ae937b0c8b3c |
|
BLAKE2b-256 | f59fe38e2885daae08424722a3c2b20fa222f141f6ab54d0ddc264464de8093e |