contained


Namecontained JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryEnable function chaining for any object
upload_time2022-12-09 23:52:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords functional composition pipline chaining
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Enable function chaining for any object.

Contained is a class that can wrap any type and make it possible to do function
chaining on that object, much like functional piping.

Any method that is defined on the contained type is possible to call, whether it
returns a copy or mutates in place. It is also possible to call operators and
any builtin function, without breaking the chain. To get the original variable
back out of the Contained, just call it with no args.

```python
from contained import Contained
ex = ['hello', 'world']
Contained(ex)() == ex  # True

# methods
Contained(['hello']).extend(['world'])() == ex  # True

# operators
Contained(['hello']).add(['world']).contains('hello')()  # True

# builtins
Contained(ex).len().type()()  # <class 'int'>
```

Contained can also be given an additional namespace to allow for custom
chained methods. This can be a module dict, class dict, globals, locals, or
any other dict mapping names to objects.

```python
def stringify_number_colleciton(c):
    return (s if not str(s).isdigit() else int(s) for s in c)

(Contained({1, "A", 3.02, ()}, additional_methods=locals())
    .stringify_number_colleciton()
    .sorted(key=lambda s: str(s))
    () == 
[(), 1, 3.02, 'A'])
```

```python
import functools, itertools

# if you are on Python >= 3.9 use `additional_methods=(vars(functools) | vars(itertools))`
(Contained(42, reversed=True, additional_methods=Contained(vars(functools)).update(vars(itertools))())
    .range()
    .list()
    .takewhile(lambda x: x < 18)
    .dropwhile(lambda x: x <= 5)
    .map(hex)
    .reduce(lambda y, x: f"{y} {x}")
    () ==
"0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x11")
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "contained",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "functional,composition,pipline,chaining",
    "author": null,
    "author_email": "Jeremiah Paige <ucodery@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/07/d2/fe4a1b16710d09efdc80f0328889a36f7f25ea8c29b872f586b2aef8de08/contained-0.0.2.tar.gz",
    "platform": null,
    "description": "Enable function chaining for any object.\n\nContained is a class that can wrap any type and make it possible to do function\nchaining on that object, much like functional piping.\n\nAny method that is defined on the contained type is possible to call, whether it\nreturns a copy or mutates in place. It is also possible to call operators and\nany builtin function, without breaking the chain. To get the original variable\nback out of the Contained, just call it with no args.\n\n```python\nfrom contained import Contained\nex = ['hello', 'world']\nContained(ex)() == ex  # True\n\n# methods\nContained(['hello']).extend(['world'])() == ex  # True\n\n# operators\nContained(['hello']).add(['world']).contains('hello')()  # True\n\n# builtins\nContained(ex).len().type()()  # <class 'int'>\n```\n\nContained can also be given an additional namespace to allow for custom\nchained methods. This can be a module dict, class dict, globals, locals, or\nany other dict mapping names to objects.\n\n```python\ndef stringify_number_colleciton(c):\n    return (s if not str(s).isdigit() else int(s) for s in c)\n\n(Contained({1, \"A\", 3.02, ()}, additional_methods=locals())\n    .stringify_number_colleciton()\n    .sorted(key=lambda s: str(s))\n    () == \n[(), 1, 3.02, 'A'])\n```\n\n```python\nimport functools, itertools\n\n# if you are on Python >= 3.9 use `additional_methods=(vars(functools) | vars(itertools))`\n(Contained(42, reversed=True, additional_methods=Contained(vars(functools)).update(vars(itertools))())\n    .range()\n    .list()\n    .takewhile(lambda x: x < 18)\n    .dropwhile(lambda x: x <= 5)\n    .map(hex)\n    .reduce(lambda y, x: f\"{y} {x}\")\n    () ==\n\"0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x11\")\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Enable function chaining for any object",
    "version": "0.0.2",
    "split_keywords": [
        "functional",
        "composition",
        "pipline",
        "chaining"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "md5": "5c8a6a974f99154f2ba4d1b8f52ea2ea",
                "sha256": "ba15152bf006f443ceb9e051583bc7b584a74a466c425c7c7e5aaa1544b139eb"
            },
            "downloads": -1,
            "filename": "contained-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5c8a6a974f99154f2ba4d1b8f52ea2ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 3213,
            "upload_time": "2022-12-09T23:51:53",
            "upload_time_iso_8601": "2022-12-09T23:51:53.251486Z",
            "url": "https://files.pythonhosted.org/packages/0b/f3/7428191f018ba029bb33b78a0ae06958c0b3005a6567ae0c13b02882ae8c/contained-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "md5": "8e8836077edb586b5777dc2e8b123012",
                "sha256": "62445ef57fe2b40ea636d62c972c53ca3750b80cd0759d1cd79598ea301e97f9"
            },
            "downloads": -1,
            "filename": "contained-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8e8836077edb586b5777dc2e8b123012",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 4041,
            "upload_time": "2022-12-09T23:52:01",
            "upload_time_iso_8601": "2022-12-09T23:52:01.077727Z",
            "url": "https://files.pythonhosted.org/packages/07/d2/fe4a1b16710d09efdc80f0328889a36f7f25ea8c29b872f586b2aef8de08/contained-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-09 23:52:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "contained"
}
        
Elapsed time: 0.01756s