Package: lz
lzIn what followspythonis an alias forpython3.7orpypy3.7or any later version (python3.8,pypy3.8and so on).InstallationInstall the latestpip&setuptoolspackages versionspython-mpipinstall--upgradepipsetuptoolsUserDownload and install the latest stable version fromPyPIrepositorypython-mpipinstall--upgradelzDeveloperDownload the latest version fromGitHubrepositorygitclonehttps://github.com/lycantropos/lz.gitcdlzInstall dependenciespython-mpipinstall-rrequirements.txtInstallpythonsetup.pyinstallUsagelzprovides a bunch of utilities for working with functions, predicates & iterables such asfunction composition>>>fromlz.functionalimportcompose>>>sum_of_first_n_natural_numbers=compose(sum,range)>>>sum_of_first_n_natural_numbers(10)45currying>>>fromlz.functionalimportcurry>>>curried_power=curry(pow)>>>two_to_power=curried_power(2)>>>two_to_power(10)1024flipping positional parameters order>>>fromlz.functionalimportflip>>>flipped_power=flip(pow)>>>flipped_power(2,3)9packing function's arguments>>>fromlz.functionalimportpack>>>packed_int=pack(int)>>>packed_int(['10'])10>>>packed_int(['10'],{'base':2})2leftpartial application>>>fromlzimportleft>>>count_from_zero_to=left.applier(range,0)>>>list(count_from_zero_to(10))[0,1,2,3,4,5,6,7,8,9]rightpartial application>>>fromlzimportright>>>square=right.applier(pow,2)>>>square(10)100negatingpredicate>>>fromlz.logicalimportnegate>>>false_like=negate(bool)>>>false_like([])True>>>false_like([0])Falseconjoiningpredicates>>>fromlz.logicalimportconjoin>>>is_valid_constant_identifier=conjoin(str.isupper,str.isidentifier)>>>is_valid_constant_identifier('SECOND_SECTION')True>>>is_valid_constant_identifier('2ND_SECTION')Falsedisjoiningpredicates>>>fromlz.logicalimportdisjoin>>>alphabetic_or_numeric=disjoin(str.isalpha,str.isnumeric)>>>alphabetic_or_numeric('Hello')True>>>alphabetic_or_numeric('42')True>>>alphabetic_or_numeric('Hello42')Falseexclusive disjoiningpredicates>>>fromlz.logicalimportexclusive_disjoin>>>fromkeywordimportiskeyword>>>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')Falsereversing sequences and any string streams>>>fromlz.reversalimportreverse>>>list(reverse(range(10)))[9,8,7,6,5,4,3,2,1,0]>>>importio>>>list(reverse(io.BytesIO(b'Hello\nWorld!')))[b'World!',b'Hello\n']chunking iterable>>>fromlz.iteratingimportchopper>>>to_triplets=chopper(3)>>>list(map(tuple,to_triplets(range(10))))[(0,1,2),(3,4,5),(6,7,8),(9,)]sliding over iterable>>>fromlz.iteratingimportslider>>>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)]interleavingiterables>>>fromlz.iteratingimportinterleave>>>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]iterabletransposition>>>fromlz.transpositionimporttranspose>>>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>>>fromlz.replicationimportduplicate>>>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)]andmany more.DevelopmentBuilding docsInstall project in editable modepython-mpipinstall-e.Install dependenciespython-mpipinstall-rdocs/requirements.txtBuild docscddocs
makehtmlBumping versionPreparationInstallbump2version.Pre-releaseChoose which version number category to bump followingsemver
specification.Test bumping versionbump2version--dry-run--verbose$CATEGORYwhere$CATEGORYis the target version number category name, possible
values arepatch/minor/major.Bump versionbump2version--verbose$CATEGORYThis will set version tomajor.minor.patch-alpha.ReleaseTest bumping versionbump2version--dry-run--verbosereleaseBump versionbump2version--verbosereleaseThis will set version tomajor.minor.patch.Running testsInstall dependenciespython-mpipinstall-rrequirements-tests.txtPlainpytestInsideDockercontainer:withCPythondocker-compose--filedocker-compose.cpython.ymlupwithPyPydocker-compose--filedocker-compose.pypy.ymlupBashscript (e.g. can be used inGithooks):withCPython./run-tests.shor./run-tests.shcpythonwithPyPy./run-tests.shpypyPowerShellscript (e.g. can be used inGithooks):withCPython.\run-tests.ps1or.\run-tests.ps1cpythonwithPyPy.\run-tests.ps1pypy