{ "info": { "author": "Kim Hermansson", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries" ], "description": "# State pattern \n\n**The state pattern tries to deal with common state issues by making it immutable and utilizing copy-on-write.**\n\nThis pattern kind of emerged for me out of necessity while working with databases. I had inherited quite a bit of code that was analyzing, creating, editing, and removing data, all in a couple of quite large, borderline godlike, functions.\n\nI can't get into too much detail, but more often than not, the same bit of data was fetched over and over, making it slow. Sometimes bits of the code was working on data that had already been edited by other bits of the code, and whenever there was an error, it tended to leave the data in a very iffy state.\n\nI did not like this one bit.\n\nFurther reading: http://segfaultsourcery.com/post/state-pattern\n\n## Installation\n\n### Requirements\n* Python 3.5 and up\n\n`$ pip install statepattern`\n\n## Usage\n\nThis example shows how to assign and reassign values in a `State` object.\n\n```python\nfrom statepattern import State as S\n\nstate1 = S(\n dog='water',\n horses=5,\n)\n\nstate2 = state1.assign(dog='not water', cinnamon_toast='man')\nprint(state1, state2)\n```\n\n\nThis example shows how to use a `State` object to chain function calls. A function must accept a `State` as its only argument and return a `State`.\n\n```python\nfrom statepattern import State as S\n\n\ndef increment(state: S) -> S:\n points = state.points or 0\n return state.assign(points=points + 1)\n\n\ndef double(state: S) -> S:\n points = state.points or 0\n return state.assign(points=points * 2)\n\n\nbefore = S(points=0)\n\nafter = (\n before\n .then(increment)\n .then(double)\n .then(increment)\n)\n\nprint(before, after)\n```\n\nThis example shows how to discard a value by key.\n\n```python\nfrom statepattern import State as S\n\nstate1 = S(\n dog='water',\n horses=5,\n)\n\nstate2 = state1.discard('dog')\nprint(state1, state2)\n```\n\n\n## Development\nThere are no dependencies at all, by design. I still recommend making a virtualenv to work in, however.\n```\n$ virtualenv venv\n$ source venv/bin/activate\n$ pip install -e .\n```\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update (or write) tests as appropriate.\n\n## License\n[BSD 2-Clause License](https://tldrlegal.com/license/bsd-2-clause-license-(freebsd))", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/segfaultsourcery/state-pattern", "keywords": "productivity development method-chains functional", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "statepattern", "package_url": "https://pypi.org/project/statepattern/", "platform": "", "project_url": "https://pypi.org/project/statepattern/", "project_urls": { "Homepage": "https://github.com/segfaultsourcery/state-pattern" }, "release_url": "https://pypi.org/project/statepattern/1.0.0/", "requires_dist": null, "requires_python": "~=3.5", "summary": "Object used to maintain state.", "version": "1.0.0" }, "last_serial": 4295581, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "40360e87229b19c8bab1582d73363ca0", "sha256": "1fa02410766bf5194060b684728fd9a09bce8aa576d8bcff3a641e1cccce2d0b" }, "downloads": -1, "filename": "statepattern-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "40360e87229b19c8bab1582d73363ca0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": "~=3.5", "size": 3130, "upload_time": "2018-08-30T17:32:01", "url": "https://files.pythonhosted.org/packages/f6/40/9793fb494e56ce55310b86196f30abf9036fe1c368a2fbae8aad48c77732/statepattern-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d3c79aa762e3b06db3d76b81a7320155", "sha256": "c04673fd2614d387ce3d39302faa2c7eecab338924e9a738a30bac94a5f1e95c" }, "downloads": -1, "filename": "statepattern-0.1.0.tar.gz", "has_sig": false, "md5_digest": "d3c79aa762e3b06db3d76b81a7320155", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.5", "size": 3057, "upload_time": "2018-08-30T17:32:02", "url": "https://files.pythonhosted.org/packages/41/f9/41bba19f22fa6599edc3d58e2af796dbd4ac57150cbf6d2616a4b6901261/statepattern-0.1.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "520e6f2fe46a703dbba1eb684694ce53", "sha256": "8a9ec6072f7ad9b93abb483f9b7ac32d90a1955b8d13e3cccf5a0ee99be45265" }, "downloads": -1, "filename": "statepattern-1.0.0.tar.gz", "has_sig": false, "md5_digest": "520e6f2fe46a703dbba1eb684694ce53", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.5", "size": 4170, "upload_time": "2018-09-21T09:39:05", "url": "https://files.pythonhosted.org/packages/2d/57/82465d18372f7e0ded85f41ff9909ae7dd2bb771052e742151d66cac4db2/statepattern-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "520e6f2fe46a703dbba1eb684694ce53", "sha256": "8a9ec6072f7ad9b93abb483f9b7ac32d90a1955b8d13e3cccf5a0ee99be45265" }, "downloads": -1, "filename": "statepattern-1.0.0.tar.gz", "has_sig": false, "md5_digest": "520e6f2fe46a703dbba1eb684694ce53", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.5", "size": 4170, "upload_time": "2018-09-21T09:39:05", "url": "https://files.pythonhosted.org/packages/2d/57/82465d18372f7e0ded85f41ff9909ae7dd2bb771052e742151d66cac4db2/statepattern-1.0.0.tar.gz" } ] }