predica


Namepredica JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryPredicates for use in higher-order functions.
upload_time2023-12-08 21:25:47
maintainer
docs_urlNone
authorRahul Yadav
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Rahul Yadav Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords composition fp functional programming predicates type-safety
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # predica

-----

Predicates for use in higher-order functions.

## Installation

```bash
pip install predica
```

## Usage

Let's illustrate usage with three examples, gradually improving the composability of the code:

Simple example -

```python
from predica import P  # you can import `Predicates` too

ages = [1, 10, 100, 1000, '1']

# before
ages_no_str = list(filter(lambda x: not isinstance(x, str), ages)) # [1, 10, 100, 1000]

# after
new_ages_no_str = list(filter(P.not_instanceof(str), ages)) # [1, 10, 100, 1000]
```

Suppose you have a pre-existing function `is_str` -

```python
def is_str(x: str) -> bool:
    return isinstance(x, str)

# before
ages_no_str = list(filter(lambda x: not is_str(x), ages))  # [1, 10, 100, 1000]

# after
new_ages_no_str = list(filter(P.negation(is_str), ages))  # [1, 10, 100, 1000]
```

IMO this works best with `returns` [library](https://github.com/dry-python/returns) 
(and is why I made this library to begin with) -


```python
from returns.result import Result
from functools import partial

ages = Result.from_value([1, 10, 100, 1000, '1'])

ages.map(partial(filter, P.not_instanceof(str))).map(list)  # Success([1, 10, 100, 1000])
# or
ages.map(partial(filter, P.negation(is_str))).map(list)  # Success([1, 10, 100, 1000])
```

Much better 😮

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "predica",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "composition,fp,functional programming,predicates,type-safety",
    "author": "Rahul Yadav",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/97/f6/0af531b36a3532697e19f81e2d43a08de09b32e5ee228d06d04217555c52/predica-0.1.1.tar.gz",
    "platform": null,
    "description": "# predica\n\n-----\n\nPredicates for use in higher-order functions.\n\n## Installation\n\n```bash\npip install predica\n```\n\n## Usage\n\nLet's illustrate usage with three examples, gradually improving the composability of the code:\n\nSimple example -\n\n```python\nfrom predica import P  # you can import `Predicates` too\n\nages = [1, 10, 100, 1000, '1']\n\n# before\nages_no_str = list(filter(lambda x: not isinstance(x, str), ages)) # [1, 10, 100, 1000]\n\n# after\nnew_ages_no_str = list(filter(P.not_instanceof(str), ages)) # [1, 10, 100, 1000]\n```\n\nSuppose you have a pre-existing function `is_str` -\n\n```python\ndef is_str(x: str) -> bool:\n    return isinstance(x, str)\n\n# before\nages_no_str = list(filter(lambda x: not is_str(x), ages))  # [1, 10, 100, 1000]\n\n# after\nnew_ages_no_str = list(filter(P.negation(is_str), ages))  # [1, 10, 100, 1000]\n```\n\nIMO this works best with `returns` [library](https://github.com/dry-python/returns) \n(and is why I made this library to begin with) -\n\n\n```python\nfrom returns.result import Result\nfrom functools import partial\n\nages = Result.from_value([1, 10, 100, 1000, '1'])\n\nages.map(partial(filter, P.not_instanceof(str))).map(list)  # Success([1, 10, 100, 1000])\n# or\nages.map(partial(filter, P.negation(is_str))).map(list)  # Success([1, 10, 100, 1000])\n```\n\nMuch better \ud83d\ude2e\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Rahul Yadav  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Predicates for use in higher-order functions.",
    "version": "0.1.1",
    "project_urls": {
        "Issues": "https://github.com/y-src/predica/issues",
        "Repository": "https://github.com/y-src/predica"
    },
    "split_keywords": [
        "composition",
        "fp",
        "functional programming",
        "predicates",
        "type-safety"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "852cacc0812ca1e224f80b1dbe2493b4b1142ef1d9d9841f8f3d7e72ad472629",
                "md5": "59d4b57cf11a8b4dc69cb2001f88948b",
                "sha256": "cd170f2e1320ba9ce0bcd5d99ae774f76c91c4caca6a0b36e1f603a4abcd6166"
            },
            "downloads": -1,
            "filename": "predica-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "59d4b57cf11a8b4dc69cb2001f88948b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4334,
            "upload_time": "2023-12-08T21:25:45",
            "upload_time_iso_8601": "2023-12-08T21:25:45.975024Z",
            "url": "https://files.pythonhosted.org/packages/85/2c/acc0812ca1e224f80b1dbe2493b4b1142ef1d9d9841f8f3d7e72ad472629/predica-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97f60af531b36a3532697e19f81e2d43a08de09b32e5ee228d06d04217555c52",
                "md5": "e9159ca10b5a19f2076d2ab36bd9c9aa",
                "sha256": "e4da5f9d4b3bcdc99fe0b3770e89f3a41aa7c8fae26339b7886bbe725afd4929"
            },
            "downloads": -1,
            "filename": "predica-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e9159ca10b5a19f2076d2ab36bd9c9aa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 5706,
            "upload_time": "2023-12-08T21:25:47",
            "upload_time_iso_8601": "2023-12-08T21:25:47.177297Z",
            "url": "https://files.pythonhosted.org/packages/97/f6/0af531b36a3532697e19f81e2d43a08de09b32e5ee228d06d04217555c52/predica-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-08 21:25:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "y-src",
    "github_project": "predica",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "predica"
}
        
Elapsed time: 0.13558s