{ "info": { "author": "Joe Lawson", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Parameter Pack\r\n--------------\r\n\r\nThis module provides a mechanism for writing something similar to C++17's `fold expressions`_ in Python. This is\r\nachieved by co-opting Python's mostly unused ``Ellipsis`` literal.\r\n\r\n\r\nSupported Operators\r\n-------------------\r\n\r\n- Addition (``+``)\r\n- Subtraction (``-``)\r\n- Multiplication (``*``)\r\n- Integer division (``//``)\r\n- Division (``/``)\r\n- Modulus (``%``)\r\n- Matrix Multiplication (``@``, Python >= 3.5 only)\r\n- Bitwise And (``&``)\r\n- Bitwise Or (``|``)\r\n- Bitwise Xor (``^``)\r\n- Left Shift (``<<``)\r\n- Right Shift (``>>``)\r\n- ``__call__``\r\n- Comparison operators (``>``, ``>=``, ``<``, ``<=``, ``==``, ``!=``)\r\n\r\n\r\nExamples\r\n--------\r\n\r\nThere are two ways to \"fold\" an operation over a parameter pack: *left* and *right* folds.\r\n\r\n.. code-block:: python\r\n\r\n from parameterpack import pack\r\n\r\n p = pack(1, 2, 3)\r\n\r\n # Left fold\r\n p - ... # (1 - 2) - 3 = -4\r\n p - ... - 4 # ((1 - 2) - 3) - 4 = -8\r\n\r\n # Right fold\r\n ... - p # 1 - (2 - 3) = 2\r\n ... - p - 4 # 4 - (1 - (2 - 3)) = -2\r\n\r\nNote that the left fold groups operations on the left, while the right fold groups them on the right. This only makes\r\na difference if the folded operation is not associative, such as in the case of integer subtraction.\r\n\r\nBecause it is not possible to redefine the ``ellipsis`` type's operators, a right fold on the right side of a binary\r\noperation requires parentheses.\r\n\r\n.. code-block:: python\r\n\r\n from parameterpack import pack\r\n\r\n p = pack(1, 2, 3)\r\n\r\n # This is an error because \"4 - ...\" is evaluated first.\r\n 4 - ... - p\r\n\r\n # This is what you should do instead.\r\n 4 - (... - p) # 4 - (3 - (2 - 1)) = 2\r\n\r\nYou may prefer to use parentheses in every case to keep the syntax clear and avoid this potential oversight.\r\n\r\nConditional chains are also supported, but they work a little differently from the other folds.\r\n\r\n.. code-block:: python\r\n\r\n from parameterpack import pack\r\n\r\n p = pack(1, 2, 3)\r\n\r\n # Python evaluates \"a < b < c\" as \"a < b and b < c\", so this module does the same.\r\n p < ... # 1 < 2 < 3 = True, so 3 is returned.\r\n p < ... < 4 # 1 < 2 < 3 < 4 = True\r\n p < ... < 0 # 1 < 2 < 3 < 0 = False\r\n\r\n p = pack(3, 2, 1)\r\n\r\n p < ... # 3 < 2 < 1 = False, so a special False-comparing object is returned.\r\n ... < p # 3 > 2 > 1 = True\r\n\r\nBecause python has no reversed-argument forms for the comparison operators, conditionals work a little differently.\r\nIf folding the comparison over the parameter pack's elements results in ``False``, in order to invalidate the entire\r\ncomparison chain, it will return a special object that will return ``False`` for any further comparisons. Otherwise, the\r\nlast element of the parameter pack is returned so that the comparison chain can continue.\r\n\r\n\r\nRunning Tests\r\n-------------\r\n\r\nTo run this module's tests in your system's Python interpreter, simply run ``python setup.py test`` from the\r\nrepository root.\r\n\r\nTo run tests in all supported interpreters, first ensure that every supported Python interpreter is installed on your\r\nsystem and added to the `PATH` environment variable. Then run ``pip install -e .[dev]`` from the repository root to\r\ninstall development dependencies, and then run ``tox`` from the repository root to run the tests.\r\n\r\n\r\nBugs Reports and Feature Requests\r\n---------------------------------\r\n\r\nPlease use the `issue tracker`_ to submit bugs or request features.\r\n\r\n\r\nLicense\r\n-------\r\n\r\nCopyright Joe Lawson, 2017.\r\n\r\nThis package is distributed under the terms of the `MIT`_ license.\r\n\r\n.. _`MIT`: https://github.com/TehJoE/parameterpack/blob/master/LICENSE\r\n.. _`fold expressions`: http://en.cppreference.com/w/cpp/language/fold\r\n.. _`issue tracker`: https://github.com/TehJoE/parameterpack/issues", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/TehJoE/parameterpack", "keywords": "development fold functional pack unpack", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "parameterpack", "package_url": "https://pypi.org/project/parameterpack/", "platform": "", "project_url": "https://pypi.org/project/parameterpack/", "project_urls": { "Homepage": "https://github.com/TehJoE/parameterpack" }, "release_url": "https://pypi.org/project/parameterpack/0.1.0/", "requires_dist": [ "bumpversion; extra == 'dev'", "tox; extra == 'dev'" ], "requires_python": "", "summary": "Ellipsis trickery for enabling fold expressions", "version": "0.1.0" }, "last_serial": 2995544, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "92101a6f5078cbba41c7723b3ecf6dc0", "sha256": "da4454ed61df9ec3debbba2fe1bc5a91be15705a3dd12fad660cdef6e69da4f6" }, "downloads": -1, "filename": "parameterpack-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "92101a6f5078cbba41c7723b3ecf6dc0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6875, "upload_time": "2017-07-02T23:41:11", "url": "https://files.pythonhosted.org/packages/2f/2e/a01d871920154f25708d0b20fb745deb9b604195962debfea62b6002ea82/parameterpack-0.1.0-py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "92101a6f5078cbba41c7723b3ecf6dc0", "sha256": "da4454ed61df9ec3debbba2fe1bc5a91be15705a3dd12fad660cdef6e69da4f6" }, "downloads": -1, "filename": "parameterpack-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "92101a6f5078cbba41c7723b3ecf6dc0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6875, "upload_time": "2017-07-02T23:41:11", "url": "https://files.pythonhosted.org/packages/2f/2e/a01d871920154f25708d0b20fb745deb9b604195962debfea62b6002ea82/parameterpack-0.1.0-py3-none-any.whl" } ] }