Skip to main content

"Lazy" calculations support.

Project description

lz

In what follows

  • python is an alias for python3.5 or any later version (python3.6 and so on),
  • pypy is an alias for pypy3.5 or any later version (pypy3.6 and so on).

Installation

Install the latest pip & setuptools packages versions:

  • with CPython
    python -m pip install --upgrade pip setuptools
    
  • with PyPy
    pypy -m pip install --upgrade pip setuptools
    

User

Download and install the latest stable version from PyPI repository:

  • with CPython
    python -m pip install --upgrade lz
    
  • with PyPy
    pypy -m pip install --upgrade lz
    

Developer

Download the latest version from GitHub repository

git clone https://github.com/lycantropos/lz.git
cd lz

Install:

  • with CPython
    python setup.py install
    
  • with PyPy
    pypy setup.py install
    

Usage

lz provides a bunch of utilities for working with functions, predicates & iterables such as

  1. function composition

    >>> from lz.functional import compose
    >>> from functools import partial
    >>> sum_of_digits = compose(sum,
                                partial(map, int),
                                str)
    >>> sum_of_digits(1234)
    10
    
  2. currying

    >>> from lz.functional import curry 
    >>> curried_power = curry(pow) 
    >>> two_to_power = curried_power(2) 
    >>> list(map(two_to_power, range(10))) 
    [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]
    
  3. flipping positional parameters order

    >>> from lz.functional import flip
    >>> flipped_power = flip(pow)
    >>> flipped_power(2, 4)
    16
    
  4. packing function's arguments

    >>> from lz.functional import pack
    >>> packed_int = pack(int)
    >>> packed_int(['10'])
    10
    >>> packed_int(['10'], {'base': 2})
    2
    
  5. 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]
    
  6. right partial application

    >>> from lz import right
    >>> square = right.applier(pow, 2)
    >>> square(10)
    100
    
  7. negating predicate

    >>> from lz.logical import negate
    >>> false_like = negate(bool)
    >>> false_like([])
    True
    >>> false_like([0])
    False
    
  8. 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
    
  9. 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
    
  10. reversing iterable

    >>> from lz.iterating import reverse
    >>> list(reverse(range(10)))
    [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
    
  11. chunking iterable

    >>> from lz.iterating import chopper
    >>> to_triplets = chopper(3)
    >>> list(to_triplets(range(10)))
    [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9,)]
    
  12. 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)]
    

and many more.

Development

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 --tag release

Bump version

bump2version --verbose --tag release

This will set version to major.minor.patch and add Git tag.

Notes

To avoid inconsistency between branches and pull requests, bumping version should be merged into master branch as separate pull request.

Running tests

Plain:

  • with CPython
    python setup.py test
    
  • with PyPy
    pypy setup.py test
    

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lz-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

lz-0.1.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file lz-0.1.0.tar.gz.

File metadata

  • Download URL: lz-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for lz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1a0870fed005b81f4947ce04a141c21692e8ef3b82e2c91b80ee89b89ad4728e
MD5 296476a248895e4fca26728698ef89c6
BLAKE2b-256 3b8ede82a2f1b3db61eeddde9223992ac1109b50049e11af9490a3e85d5d67ce

See more details on using hashes here.

Provenance

File details

Details for the file lz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

File hashes

Hashes for lz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 434bc6ad48ea6e856b51ca72358340642db70b0b6d8a05c7684d847f382b61fa
MD5 cb584bd5a490c7d8a5e6f79269d87fe9
BLAKE2b-256 0b625351c9299f3c064896a8b2c1bd6737369616f74e99c60f649d5b0a7e8a17

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page