placeholder


Nameplaceholder JSON
Version 1.4 PyPI version JSON
download
home_page
SummaryOperator overloading for fast anonymous functions.
upload_time2022-09-14 00:41:48
maintainer
docs_urlNone
author
requires_python>=3.7
licenseCopyright 2022 Aric Coady Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
keywords functional lambda scala underscore
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![image](https://img.shields.io/pypi/v/placeholder.svg)](https://pypi.org/project/placeholder/)
![image](https://img.shields.io/pypi/pyversions/placeholder.svg)
[![image](https://pepy.tech/badge/placeholder)](https://pepy.tech/project/placeholder)
![image](https://img.shields.io/pypi/status/placeholder.svg)
[![image](https://github.com/coady/placeholder/workflows/build/badge.svg)](https://github.com/coady/placeholder/actions)
[![image](https://codecov.io/gh/coady/placeholder/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/placeholder/)
 [![image](https://github.com/coady/placeholder/workflows/codeql/badge.svg)](https://github.com/coady/placeholder/security/code-scanning)
[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![image](http://mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

A `placeholder` uses operator overloading to create partially bound functions on-the-fly. When used in a binary expression, it will return a callable object with the other argument bound. It's useful for replacing `lambda` in functional programming, and resembles Scala's placeholders.

## Usage
```python
from placeholder import _     # single underscore

_.age < 18     # lambda obj: obj.age < 18
_[key] ** 2    # lambda obj: obj[key] ** 2
```

Note `_` has special meaning in other contexts, such as the previous output in interactive shells. Assign to a different name as needed. Kotlin uses `it`, but in Python `it` is a common short name for an iterator.

`_` is a singleton of an `F` class, and `F` expressions can also be used with functions.

```python
from placeholder import F

-F(len)        # lambda obj: -len(obj)
```

All applicable double underscore methods are supported.

## Performance
Every effort is made to optimize the placeholder instance. It's 20-40x faster than similar libraries on PyPI.

Placeholders are also iterable, allowing direct access to the underlying functions.

```python
(func,) = _.age  # operator.attrgetter('age')
```

Performance should generally be comparable to inlined expressions, and faster than lambda. Below are some example benchmarks.

```python
min(data, key=operator.itemgetter(-1))    # 1x
min(data, key=_[-1])                      # 1.3x
min(data, key=lambda x: x[-1])            # 1.6x
```

## Installation
```console
% pip install placeholder
```

## Tests
100% branch coverage.

```console
% pytest [--cov]
```

## Changes
1.4

* Stable abi wheels
* Removed `func` attribute

1.3

* Python >=3.7 required
* Deprecated accessing `func` attribute of partial object

1.2.1

* Setup fix

1.2

* Python >=3.6 required
* Optimized `partial` implementation

1.1

* Additional unary functions

1.0

* Removed `__` (double underscore)
* Variable arguments of first function
* Method callers and multi-valued getters

0.7

* Deprecated `__` (double underscore)

0.6

* Optimized composite functions
* Renamed to `_` (single underscore) for consistency

0.5

* Unary operators
* `__call__` implements `methodcaller`
* `__getitem__` supports only single argument
* Improved error handling
* `composer` object deprecated in favor of optimized `F` expression

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "placeholder",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "functional,lambda,scala,underscore",
    "author": "",
    "author_email": "Aric Coady <aric.coady@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ac/83/cb538e76c103fc21c9e43f6f4965c5c4d05e7a7340dc680c3150d66834d8/placeholder-1.4.tar.gz",
    "platform": null,
    "description": "[![image](https://img.shields.io/pypi/v/placeholder.svg)](https://pypi.org/project/placeholder/)\n![image](https://img.shields.io/pypi/pyversions/placeholder.svg)\n[![image](https://pepy.tech/badge/placeholder)](https://pepy.tech/project/placeholder)\n![image](https://img.shields.io/pypi/status/placeholder.svg)\n[![image](https://github.com/coady/placeholder/workflows/build/badge.svg)](https://github.com/coady/placeholder/actions)\n[![image](https://codecov.io/gh/coady/placeholder/branch/main/graph/badge.svg)](https://codecov.io/gh/coady/placeholder/)\n [![image](https://github.com/coady/placeholder/workflows/codeql/badge.svg)](https://github.com/coady/placeholder/security/code-scanning)\n[![image](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)\n[![image](http://mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\nA `placeholder` uses operator overloading to create partially bound functions on-the-fly. When used in a binary expression, it will return a callable object with the other argument bound. It's useful for replacing `lambda` in functional programming, and resembles Scala's placeholders.\n\n## Usage\n```python\nfrom placeholder import _     # single underscore\n\n_.age < 18     # lambda obj: obj.age < 18\n_[key] ** 2    # lambda obj: obj[key] ** 2\n```\n\nNote `_` has special meaning in other contexts, such as the previous output in interactive shells. Assign to a different name as needed. Kotlin uses `it`, but in Python `it` is a common short name for an iterator.\n\n`_` is a singleton of an `F` class, and `F` expressions can also be used with functions.\n\n```python\nfrom placeholder import F\n\n-F(len)        # lambda obj: -len(obj)\n```\n\nAll applicable double underscore methods are supported.\n\n## Performance\nEvery effort is made to optimize the placeholder instance. It's 20-40x faster than similar libraries on PyPI.\n\nPlaceholders are also iterable, allowing direct access to the underlying functions.\n\n```python\n(func,) = _.age  # operator.attrgetter('age')\n```\n\nPerformance should generally be comparable to inlined expressions, and faster than lambda. Below are some example benchmarks.\n\n```python\nmin(data, key=operator.itemgetter(-1))    # 1x\nmin(data, key=_[-1])                      # 1.3x\nmin(data, key=lambda x: x[-1])            # 1.6x\n```\n\n## Installation\n```console\n% pip install placeholder\n```\n\n## Tests\n100% branch coverage.\n\n```console\n% pytest [--cov]\n```\n\n## Changes\n1.4\n\n* Stable abi wheels\n* Removed `func` attribute\n\n1.3\n\n* Python >=3.7 required\n* Deprecated accessing `func` attribute of partial object\n\n1.2.1\n\n* Setup fix\n\n1.2\n\n* Python >=3.6 required\n* Optimized `partial` implementation\n\n1.1\n\n* Additional unary functions\n\n1.0\n\n* Removed `__` (double underscore)\n* Variable arguments of first function\n* Method callers and multi-valued getters\n\n0.7\n\n* Deprecated `__` (double underscore)\n\n0.6\n\n* Optimized composite functions\n* Renamed to `_` (single underscore) for consistency\n\n0.5\n\n* Unary operators\n* `__call__` implements `methodcaller`\n* `__getitem__` supports only single argument\n* Improved error handling\n* `composer` object deprecated in favor of optimized `F` expression\n",
    "bugtrack_url": null,
    "license": "Copyright 2022 Aric Coady  Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
    "summary": "Operator overloading for fast anonymous functions.",
    "version": "1.4",
    "split_keywords": [
        "functional",
        "lambda",
        "scala",
        "underscore"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "cf3e4fcf5b248cc28697d01d16b434a4",
                "sha256": "75e9e380d22347439ff22eeb1ec16d440bed7977ae2ec865b62167eb36246f22"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-macosx_10_9_x86_64.whl",
            "has_sig": false,
            "md5_digest": "cf3e4fcf5b248cc28697d01d16b434a4",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 8013,
            "upload_time": "2022-09-14T00:46:06",
            "upload_time_iso_8601": "2022-09-14T00:46:06.319851Z",
            "url": "https://files.pythonhosted.org/packages/79/5b/46e381eb331222e33e28dc114c698af9187d93f8cc68e9a86fd9e664260d/placeholder-1.4-cp37-abi3-macosx_10_9_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ea7d12cfd475997b5785dafa4013667d",
                "sha256": "11f1693be323fb264379c26365ed0177bfcb5d77fe8f72619a94bacd89e0cb51"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "ea7d12cfd475997b5785dafa4013667d",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 11831,
            "upload_time": "2022-09-14T00:43:37",
            "upload_time_iso_8601": "2022-09-14T00:43:37.339988Z",
            "url": "https://files.pythonhosted.org/packages/81/a1/54ab6126ccaeea9ab45344c57a441394375425e4c849dcaaecaace24d30c/placeholder-1.4-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "26c2cb6d159a57e0fd7bb402ff1b86cc",
                "sha256": "6e1f07f147cce5aee5d1b93c9ba6e7083bd066e2ee4593f0faa93c7755ea22d9"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "26c2cb6d159a57e0fd7bb402ff1b86cc",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 12171,
            "upload_time": "2022-09-14T00:43:38",
            "upload_time_iso_8601": "2022-09-14T00:43:38.642829Z",
            "url": "https://files.pythonhosted.org/packages/53/b2/dd04a12dc1b25d472508ee162b956addf5ca3a2a282ff7ff612f1c061657/placeholder-1.4-cp37-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "a4217864bee412a34a6f254c7646aec4",
                "sha256": "0fe26e4c3174a6e2cbcc41a5b6ef280ecf213576d62dea79b4eec51a332c0c00"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-musllinux_1_1_i686.whl",
            "has_sig": false,
            "md5_digest": "a4217864bee412a34a6f254c7646aec4",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 14258,
            "upload_time": "2022-09-14T00:43:39",
            "upload_time_iso_8601": "2022-09-14T00:43:39.655661Z",
            "url": "https://files.pythonhosted.org/packages/0d/5c/5ee0e45c7333178cec69132b3a89091678cbbef45c38fe47a72b4d6962db/placeholder-1.4-cp37-abi3-musllinux_1_1_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "06bfde4000d3e5f19f1ffcb1cc567253",
                "sha256": "7397f1608e276181ad64198f42a66d0538ecb4576cf194c678954fcf5d5a8a2d"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-musllinux_1_1_x86_64.whl",
            "has_sig": false,
            "md5_digest": "06bfde4000d3e5f19f1ffcb1cc567253",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 14579,
            "upload_time": "2022-09-14T00:43:41",
            "upload_time_iso_8601": "2022-09-14T00:43:41.150920Z",
            "url": "https://files.pythonhosted.org/packages/10/bc/e1377ae69b6943d885817dd4b27de6dffa49a7d9c943dfe80b15561eff62/placeholder-1.4-cp37-abi3-musllinux_1_1_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "2ba74f8f60fb3fdeb22b55e98f305c0f",
                "sha256": "25a83ac095ccd5b6fc89c7a145883c8a30b4dcb786174cdcd08a5ec698eee75d"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-win32.whl",
            "has_sig": false,
            "md5_digest": "2ba74f8f60fb3fdeb22b55e98f305c0f",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 10782,
            "upload_time": "2022-09-14T00:44:46",
            "upload_time_iso_8601": "2022-09-14T00:44:46.013465Z",
            "url": "https://files.pythonhosted.org/packages/ef/14/3180a1e32db20c674e9ec2844c9d519a7ad2e6afae9bd1b84f7fea81ca10/placeholder-1.4-cp37-abi3-win32.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "44677750d83db715e502118229c6b4ed",
                "sha256": "1c19fbebf8efee138090a3c257898aa0ddf9ee77971f45b0fecca4710f92213f"
            },
            "downloads": -1,
            "filename": "placeholder-1.4-cp37-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "44677750d83db715e502118229c6b4ed",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": ">=3.7",
            "size": 11214,
            "upload_time": "2022-09-14T00:44:47",
            "upload_time_iso_8601": "2022-09-14T00:44:47.394910Z",
            "url": "https://files.pythonhosted.org/packages/c8/e4/89d89a80984809e6c4402ee12ec5cf4441358e36d1ffa9b7bd4c59a7ce4e/placeholder-1.4-cp37-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "737a228718dd2c7eacd7ea03319c75f9",
                "sha256": "0891879b868094937998f6f40b522de3ebf0ec99ddfdb88fc92312a833edb0eb"
            },
            "downloads": -1,
            "filename": "placeholder-1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "737a228718dd2c7eacd7ea03319c75f9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5362,
            "upload_time": "2022-09-14T00:41:48",
            "upload_time_iso_8601": "2022-09-14T00:41:48.826508Z",
            "url": "https://files.pythonhosted.org/packages/ac/83/cb538e76c103fc21c9e43f6f4965c5c4d05e7a7340dc680c3150d66834d8/placeholder-1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-14 00:41:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "placeholder"
}
        
Elapsed time: 0.01318s