pyption


Namepyption JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/luwqz1/telegrinder_templating
Summarytype Option, Some contains some value and Nothing contains absolutely nothing.
upload_time2023-08-30 17:43:25
maintainer
docs_urlNone
authorGeorgy Kritov
requires_python>=3.10,<4.0
licenseMIT
keywords python option type rust option some nothing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyption

type Option, Some contains some value and Nothing contains absolutely nothing.


Install using PyPI:

```
pip install pyption
```

* type `Option` -> *Some[*`Value`*]* | *NothingType*
* *Some(`value: Value`)*
* *NothingType()*
* *Nothing* -> `singleton`
  
Option methods:
* unwrap
* unwrap_or
* unwrap_or_other
* map
* map_or
* map_or_else
* expect

Simple example:

```python
import typing

from pyption import Some, Nothing, Option

T = typing.TypeVar("T")


def cast_obj(obj: object, tp: type[T]) -> Option[T]:
    try:
        return Some(tp(obj))
    except (TypeError, ValueError):
        return Nothing


assert cast_obj("123", int).unwrap() == 123  # ok, some value!
assert cast_obj(123, tuple[int]).unwrap_or(tuple()) == tuple()  # ok, alternate value!
assert cast_obj((("name", "Max",),), dict[str, str]).map(lambda d: d["name"]).unwrap() == "Max"  # ok, some value from map!
assert cast_obj(999, set[int])  # fail, nothing!
```

Example usage [*HERE*](https://github.com/luwqz1/pyption/blob/main/example.py)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/luwqz1/telegrinder_templating",
    "name": "pyption",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "python,option type,rust option,some nothing",
    "author": "Georgy Kritov",
    "author_email": "howluwqz1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/71/a8/4ce07f7adbc76b248f5f07451c076a1413f1157a9859cebb9e81e0e28708/pyption-1.0.0.tar.gz",
    "platform": null,
    "description": "# pyption\n\ntype Option, Some contains some value and Nothing contains absolutely nothing.\n\n\nInstall using PyPI:\n\n```\npip install pyption\n```\n\n* type `Option` -> *Some[*`Value`*]* | *NothingType*\n* *Some(`value: Value`)*\n* *NothingType()*\n* *Nothing* -> `singleton`\n  \nOption methods:\n* unwrap\n* unwrap_or\n* unwrap_or_other\n* map\n* map_or\n* map_or_else\n* expect\n\nSimple example:\n\n```python\nimport typing\n\nfrom pyption import Some, Nothing, Option\n\nT = typing.TypeVar(\"T\")\n\n\ndef cast_obj(obj: object, tp: type[T]) -> Option[T]:\n    try:\n        return Some(tp(obj))\n    except (TypeError, ValueError):\n        return Nothing\n\n\nassert cast_obj(\"123\", int).unwrap() == 123  # ok, some value!\nassert cast_obj(123, tuple[int]).unwrap_or(tuple()) == tuple()  # ok, alternate value!\nassert cast_obj(((\"name\", \"Max\",),), dict[str, str]).map(lambda d: d[\"name\"]).unwrap() == \"Max\"  # ok, some value from map!\nassert cast_obj(999, set[int])  # fail, nothing!\n```\n\nExample usage [*HERE*](https://github.com/luwqz1/pyption/blob/main/example.py)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "type Option, Some contains some value and Nothing contains absolutely nothing.",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/luwqz1/telegrinder_templating",
        "Repository": "https://github.com/luwqz1/telegrinder_templating"
    },
    "split_keywords": [
        "python",
        "option type",
        "rust option",
        "some nothing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b297cf6b83b66ccbd6f73114cde5a95cabb5f6047d24203bb9d91369dd7d0d4a",
                "md5": "4aad59edc8004431e79706bb1f5e81c8",
                "sha256": "060fc152bc790464f9a4de45a91973e83a1af525e0c1d96d4d5425c52c2d5744"
            },
            "downloads": -1,
            "filename": "pyption-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4aad59edc8004431e79706bb1f5e81c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 3437,
            "upload_time": "2023-08-30T17:43:24",
            "upload_time_iso_8601": "2023-08-30T17:43:24.008609Z",
            "url": "https://files.pythonhosted.org/packages/b2/97/cf6b83b66ccbd6f73114cde5a95cabb5f6047d24203bb9d91369dd7d0d4a/pyption-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71a84ce07f7adbc76b248f5f07451c076a1413f1157a9859cebb9e81e0e28708",
                "md5": "bc31e2eef2e31e29abe8efab18fca88f",
                "sha256": "450e9d8d4ae5bd49cb658942a002f08b9c5b554fdedd4cecf15c19c1ab69e199"
            },
            "downloads": -1,
            "filename": "pyption-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bc31e2eef2e31e29abe8efab18fca88f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 2900,
            "upload_time": "2023-08-30T17:43:25",
            "upload_time_iso_8601": "2023-08-30T17:43:25.778829Z",
            "url": "https://files.pythonhosted.org/packages/71/a8/4ce07f7adbc76b248f5f07451c076a1413f1157a9859cebb9e81e0e28708/pyption-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-30 17:43:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luwqz1",
    "github_project": "telegrinder_templating",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyption"
}
        
Elapsed time: 0.11951s