{ "info": { "author": "Andreas @blackhc Kirsch", "author_email": "blackhc+implicit_lambda@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Implicit lambdas\n\n[![Build Status](https://www.travis-ci.com/BlackHC/implicit_lambda.svg?branch=master)](https://www.travis-ci.com/BlackHC/implicit_lambda) [![codecov](https://codecov.io/gh/BlackHC/implicit_lambda/branch/master/graph/badge.svg)](https://codecov.io/gh/BlackHC/implicit_lambda) [![PyPI](https://img.shields.io/badge/PyPI-implicit_lambda-blue.svg)](https://pypi.python.org/pypi/implicit_lambda/)\n\nThis package adds support for implicit lambdas, so you can write `map(_ + 5, a_list)` instead of `map(lambda x: x + 5, a_list)`.\n\nThe code uses Python 3.7 features for brevity. The package could easily be made to work with earlier version. Please submit an issue if there is need.\n\nImplicit lambdas are implemented using code generation. They are as fast as regular lambdas when running python with `-O` to enable optimizations.\n\n```\n--------------------------------------------- benchmark: 3 tests -----------------------------------\nName (time in ns) Mean StdDev Median OPS (Mops/s)\n----------------------------------------------------------------------------------------------------\ntest_normal_lambda 196.3468 (1.01) 140.7775 (2.32) 166.9600 (1.0) 5.0930 (0.99)\ntest_il_lambda 196.6705 (1.01) 113.9049 (1.88) 171.6000 (1.03) 5.0846 (0.99)\ntest_op_chain 195.0673 (1.0) 60.6268 (1.0) 176.2300 (1.06) 5.1264 (1.0)\n----------------------------------------------------------------------------------------------------\n```\n`il_lambda` uses implicit lambdas. `normal_lambda` uses a regular lambda. `op_chain` uses functools.partial and the operator module.\n\nWithout `-O`, lambdas with a more verbose `repr` are created:\n\n```python\nassert repr(_ + 5) == \"\"\n```\n\nThis results in up to 20% slower execution for very simple expressions. (A new type is created on the fly to hold the expression and resolving a call using a custom `__call__` is sufficient to incur such a penalty.)\n\nFor more complex expressions, the overhead will become negligible.\n\nPython expressions are fully wrapped, including index operations `[]` (using `__getitem__`), member access (using `__getattribute__`) and any calls (`__calls`). This results in great flexibility.\n\nTo disambiguate between calls within the lambda and calling a lambda, implicit lambdas have to be explicitly converted into a callable/regular Python lambda.\n\n`to_lambda` turns an implicit lambda expression into a Python lambda.\n\n`auto_lambda` adds support for implicit lambdas to existing functions that take callables.\n\nWrapped versions of `builtin`, `functools` and `itertools` are provided out-of-the-box.\n\n## Installation\n\nTo install using pip, use:\n\n```\npip install implicit_lambda\n```\n\nTo run the tests, use:\n\n```\npython setup.py test\n```\n\n## Example\n\nTo enable implicit lambdas, import placeholder symbols as needed and import wrapped builtin functions to use implicit lambdas interchangably with regular ones.\n\nUsually, `to_lambda` and other helper functions don't need to be called.\n\n```python\nfrom implicit_lambda import _, x, y, to_lambda\nfrom implicit_lambda.builtins import map\n```\n\nImplicit lambda provides wrappers around all common builtins.\n\n```python\n a_list = list(range(10))\n\n mapped_list = map(_ + 2, a_list)\n\n assert list(mapped_list) == list(range(2, 12))\n```\n\nThere are also wrappers that turn builtins into lazy functions. A wrapped function provides a `._` version that can be used within an implicit lambda.\n\n```python\n mapper = to_lambda(map._(x + 2, _))\n\n mapped_list = mapper(a_list)\n\n assert list(mapped_list) == list(range(2, 12))\n```\n\nImplicit lambdas supports nested expressions\n\n```python\n mapped_list = map((_ << 3) * 3 - 23 * _ + 2, a_list)\n\n assert list(mapped_list) == list(range(2, 12))\n```\n\nMore useful reprs are available in __debug__ mode (just don't use `-O` when running python):\n\n```python\n another_lambda = to_lambda((_ << 3) * 3 - 23 * _ + 2)\n assert repr(another_lambda) == \"\"\n```\n\nor:\n\n```python\n assert (repr((_ << 3) * 3 - 23 * _ + 2) ==\n \")\"\n```\n\nImplicit lambdas support multiple arguments, too:\n\n```python\n assert to_lambda(x * y)(5, 3) == 15\n```\n\n## Performance measurement\n\nRun\n\n```python\npython -O -m pytest -k test_performance --benchmark-warmup=on --benchmark-autosave --benchmark-disable-gc\n```\n\n## Advanced features\n\nSome operators are not supported directly because returning LambdaDSL would not work (`__bool__`, `__contains__`) or it could cause issues (`__repr__`).\n\nThere are wrapped builtins (`bool._` and `repr._`) that can be used instead, or helper functions like `contains` and `not_contains` that are exported from `implicit_lambda`.\n\nAdditionally, `implicit_lambda` supports custom `arg_resolvers` that map placeholders to lambda function arguments. By default, `strict_resolver` is used. There is also `from_allowed_signatures`, which picks the first argument signature that contains all used placeholder arguments, and `flexible_args`, which supports more than a required number of arguments and a custom partial ordering of placeholders in the case of conflicts.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/blackhc/implicit_lambda", "keywords": "tools lambda placeholder", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "implicit-lambda", "package_url": "https://pypi.org/project/implicit-lambda/", "platform": "", "project_url": "https://pypi.org/project/implicit-lambda/", "project_urls": { "Homepage": "https://github.com/blackhc/implicit_lambda" }, "release_url": "https://pypi.org/project/implicit-lambda/0.4.0/", "requires_dist": [ "check-manifest ; extra == 'dev'", "coverage ; extra == 'test'", "codecov ; extra == 'test'", "pytest ; extra == 'test'", "pytest-benchmark ; extra == 'test'", "pytest-cov ; extra == 'test'", "hypothesis ; extra == 'test'" ], "requires_python": "", "summary": "Implicit lambdas with placeholder notation and code generation", "version": "0.4.0" }, "last_serial": 4657460, "releases": { "0.4.0": [ { "comment_text": "", "digests": { "md5": "bb79667e75a2bf32df581a488bbcf8bf", "sha256": "7e444975f3dcb072ece748129463f378882504d970bc63668aa5d4b87677101e" }, "downloads": -1, "filename": "implicit_lambda-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "bb79667e75a2bf32df581a488bbcf8bf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 42566, "upload_time": "2019-01-03T19:33:42", "url": "https://files.pythonhosted.org/packages/03/fd/9264bb3a936c8315f98f3cd237c8770515770bca3b1d0925fe5a0cd9e23d/implicit_lambda-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bbf159bef9d2798d494338ccccbe4f71", "sha256": "7b80b5dde454e5bdc7589e68cf804ce09f1a7dd1504ccf5942731f24761ed1da" }, "downloads": -1, "filename": "implicit_lambda-0.4.0.tar.gz", "has_sig": false, "md5_digest": "bbf159bef9d2798d494338ccccbe4f71", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21542, "upload_time": "2019-01-03T19:33:44", "url": "https://files.pythonhosted.org/packages/ef/2e/bf8c45cbf6f75bb57d9798ccbd17d8487e0f8a4310d9f9dffd1d3a51490b/implicit_lambda-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bb79667e75a2bf32df581a488bbcf8bf", "sha256": "7e444975f3dcb072ece748129463f378882504d970bc63668aa5d4b87677101e" }, "downloads": -1, "filename": "implicit_lambda-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "bb79667e75a2bf32df581a488bbcf8bf", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 42566, "upload_time": "2019-01-03T19:33:42", "url": "https://files.pythonhosted.org/packages/03/fd/9264bb3a936c8315f98f3cd237c8770515770bca3b1d0925fe5a0cd9e23d/implicit_lambda-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bbf159bef9d2798d494338ccccbe4f71", "sha256": "7b80b5dde454e5bdc7589e68cf804ce09f1a7dd1504ccf5942731f24761ed1da" }, "downloads": -1, "filename": "implicit_lambda-0.4.0.tar.gz", "has_sig": false, "md5_digest": "bbf159bef9d2798d494338ccccbe4f71", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21542, "upload_time": "2019-01-03T19:33:44", "url": "https://files.pythonhosted.org/packages/ef/2e/bf8c45cbf6f75bb57d9798ccbd17d8487e0f8a4310d9f9dffd1d3a51490b/implicit_lambda-0.4.0.tar.gz" } ] }