{ "info": { "author": "Christopher Armstrong", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "sumtypes\n========\n\n.. image:: https://travis-ci.org/radix/sumtypes.svg?branch=master\n :target: https://travis-ci.org/radix/sumtypes\n\nsumtypes provides Algebraic Data Types for Python. The main benefit is the\nimplementation of Sum Types (aka `Tagged Unions`_), which Python doesn't have\nany native representation for. Product Types are just objects with multiple\nattributes.\n\n.. _`Tagged Unions`: http://en.wikipedia.org/wiki/Tagged_union\n\nDocumentation is at https://sumtypes.readthedocs.org/\n\nThis module uses the `attrs`_ library to provide features like attribute\nvalidation and defaults.\n\n.. _`attrs`: http://pypi.python.org/pypi/attrs\n\nExample\n=======\n\nDecorate your classes to make them a sum type:\n\n.. code:: python\n\n import attr\n from sumtypes import sumtype, constructor, match\n\n @sumtype\n class MyType(object):\n # constructors specify names for their arguments\n MyConstructor = constructor('x')\n AnotherConstructor = constructor('x', 'y')\n\n # You can also make use of any feature of the attrs\n # package by using attr.ib in constructors\n ThirdConstructor = constructor(\n one=attr.ib(default=42),\n two=attr.ib(validator=attr.validators.instance_of(int)))\n\n(`attrs package`_, and `attr.ib documentation`_)\n\n.. _`attrs package`: https://pypi.python.org/pypi/attrs\n.. _`attr.ib documentation`: http://attrs.readthedocs.org/en/stable/api.html#attr.ib\n\nThen construct them by calling the constructors:\n\n.. code:: python\n\n v = MyType.MyConstructor(1)\n v2 = MyType.AnotherConstructor('foo', 2)\n\nYou can get the values from the tagged objects:\n\n.. code:: python\n\n assert v.x == 1\n assert v2.x == 'foo'\n assert v2.y == 2\n\nYou check the constructor used:\n\n.. code:: python\n\n assert type(v) is MyType.MyConstructor\n\nAnd, like Scala case classes, the constructor type is a subclass of the main\ntype:\n\n.. code:: python\n\n assert isinstance(v, MyType)\n\nAnd the tagged objects support equality:\n\n.. code:: python\n\n assert v == MyType.MyConstructor(1)\n assert v != MyType.MyConstructor(2)\n\nSimple pattern matching is also supported. To write a function over all the\ncases of a sum type:\n\n.. code:: python\n\n @match(MyType)\n class get_number(object):\n def MyConstructor(x): return x\n def AnotherConstructor(x, y): return y\n def ThirdConstructor(one, two): return one + two\n\n assert get_number(v) == 1\n assert get_number(v2) == 2\n\n``match`` ensures that all cases are handled. If you really want to write a\n'partial function' (i.e. one that doesn't cover all cases), use\n``match_partial``.\n\n\nSee Also\n========\n\nOver the past few years, the ecosystem of libraries to help with functional\nprogramming in Python has exploded. Here are some libraries I recommend:\n\n- `effect`_ - a library for isolating side-effects\n- `pyrsistent`_ - persistent (optimized immutable) data structures in Python\n- `toolz`_ - a general library of pure FP functions\n- `fn.py`_ - a Scala-inspired set of tools, including a weird lambda syntax, option type, and monads\n\n.. _`effect`: https://pypi.python.org/pypi/effect/\n.. _`pyrsistent`: https://pypi.python.org/pypi/pyrsistent/\n.. _`toolz`: https://pypi.python.org/pypi/toolz\n.. _`fn.py`: https://pypi.python.org/pypi/fn\n\n\nThanks\n======\n\nThanks to Rackspace for allowing me to work on this project, and having an\n*excellent* `open source employee contribution policy`_\n\n.. _`open source employee contribution policy`: https://www.rackspace.com/blog/rackspaces-policy-on-contributing-to-open-source/\n\n\nLicense\n=======\n\nsumtypes is licensed under the MIT license:\n\nCopyright (C) 2015 Christopher Armstrong\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/radix/sumtypes/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sumtypes", "package_url": "https://pypi.org/project/sumtypes/", "platform": "", "project_url": "https://pypi.org/project/sumtypes/", "project_urls": { "Homepage": "http://github.com/radix/sumtypes/" }, "release_url": "https://pypi.org/project/sumtypes/0.1a5/", "requires_dist": [ "attrs" ], "requires_python": "", "summary": "Algebraic types for Python (notably providing Sum Types, aka Tagged Unions)", "version": "0.1a5" }, "last_serial": 4793516, "releases": { "0.1a1": [ { "comment_text": "", "digests": { "md5": "41724e91fe4292472f7d18e4426a5339", "sha256": "f6b231662b909d22d13b8602eb6b2ec2c07b35b94a03d22adfa2a70cf37e0752" }, "downloads": -1, "filename": "sumtypes-0.1a1-py2-none-any.whl", "has_sig": false, "md5_digest": "41724e91fe4292472f7d18e4426a5339", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 6020, "upload_time": "2015-05-28T20:01:48", "url": "https://files.pythonhosted.org/packages/4e/aa/59513ca2cf218cf632e7d22180d4a4b8b3cf15179a7e02bb1d3beb71b6e1/sumtypes-0.1a1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8e95685687d46b854f8d8684072d4d36", "sha256": "16a7cee06444ccabcd4b79c4b5ae5c6e86e46722aca9b3c724f8533ac7fdfcf8" }, "downloads": -1, "filename": "sumtypes-0.1a1.tar.gz", "has_sig": false, "md5_digest": "8e95685687d46b854f8d8684072d4d36", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3418, "upload_time": "2015-05-28T20:01:52", "url": "https://files.pythonhosted.org/packages/15/ba/e2e527dfdeb37d3580f536312a037089cebf3887b38e43c1799236b250ad/sumtypes-0.1a1.tar.gz" } ], "0.1a2": [ { "comment_text": "", "digests": { "md5": "7644e5809710552fe689e8d9123c6caa", "sha256": "344070b8e364a13443b3042a103bea5d240b5d60c9ea380f4d235aaed22a8d3f" }, "downloads": -1, "filename": "sumtypes-0.1a2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "7644e5809710552fe689e8d9123c6caa", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 6020, "upload_time": "2015-05-28T20:05:39", "url": "https://files.pythonhosted.org/packages/a0/f6/bf674994c2bc17c6b3dcfb6679c8cce9f8d37ff90d8645b40eb4e08a7a66/sumtypes-0.1a2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bda08b8c9f7627cfc58d1e94aad1d37f", "sha256": "7a22a70ccd986516c83eb67def972e1c590a987439c25f5d8cf8e750ce1cb5e4" }, "downloads": -1, "filename": "sumtypes-0.1a2.tar.gz", "has_sig": false, "md5_digest": "bda08b8c9f7627cfc58d1e94aad1d37f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3444, "upload_time": "2015-05-28T20:05:42", "url": "https://files.pythonhosted.org/packages/10/ad/9c517f6e2a726b0bc375592546cfe04d89ac76da6cb8a248a50e7c633bfc/sumtypes-0.1a2.tar.gz" } ], "0.1a3": [ { "comment_text": "", "digests": { "md5": "84ec0bf0306537e502227031886f6e67", "sha256": "c83263d0bd29ac526d7d85c027c3aacb8f0bca98a2f1efdd2f32551972349a14" }, "downloads": -1, "filename": "sumtypes-0.1a3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "84ec0bf0306537e502227031886f6e67", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8342, "upload_time": "2015-05-30T02:44:15", "url": "https://files.pythonhosted.org/packages/f2/24/540a1a16626076e0a268c931ed4b8def531f6109140ed8eaa6f867f3cd6b/sumtypes-0.1a3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7efbab49262dc841fc6e49c841b9e72f", "sha256": "42a5f1c48e2a51d2fd8a5de720fd6356e13580ae674ce542551cdaf3645663aa" }, "downloads": -1, "filename": "sumtypes-0.1a3.tar.gz", "has_sig": false, "md5_digest": "7efbab49262dc841fc6e49c841b9e72f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5060, "upload_time": "2015-05-30T02:44:20", "url": "https://files.pythonhosted.org/packages/e8/6f/9995c0d549f718a05eb133f74658acb3e2b327d4eb92c99c10ab4884e083/sumtypes-0.1a3.tar.gz" } ], "0.1a4": [ { "comment_text": "", "digests": { "md5": "ffc2ea237da685c6c0dfaa66380536dd", "sha256": "75e3cb19eee073525b3154a0f67bbd7c4353754e4d8fc9f75c587a0d4296dc56" }, "downloads": -1, "filename": "sumtypes-0.1a4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ffc2ea237da685c6c0dfaa66380536dd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8428, "upload_time": "2015-06-04T20:24:42", "url": "https://files.pythonhosted.org/packages/39/07/ad1ef51374b02b9455150d5b894d4ce1069c69e4c5700968d7a217ae651b/sumtypes-0.1a4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c49f3465cb92952d1bfc2b03275b773f", "sha256": "6c317a3d1da27b56096b8348fe99e421b585cb7f7aca72114a24fa657c341a3e" }, "downloads": -1, "filename": "sumtypes-0.1a4.tar.gz", "has_sig": false, "md5_digest": "c49f3465cb92952d1bfc2b03275b773f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5145, "upload_time": "2015-06-04T20:24:46", "url": "https://files.pythonhosted.org/packages/64/39/1d2aeadf035f187237318d173642a3ba058920db27c1ae2750a470958e24/sumtypes-0.1a4.tar.gz" } ], "0.1a5": [ { "comment_text": "", "digests": { "md5": "6cab6c5fd3bb91f05cb5cb8523718b3d", "sha256": "148b45ba70b8b82c043e1a9346009b32cf13e03a1083919edf4fd76cb952a8af" }, "downloads": -1, "filename": "sumtypes-0.1a5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6cab6c5fd3bb91f05cb5cb8523718b3d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5747, "upload_time": "2019-02-07T23:29:02", "url": "https://files.pythonhosted.org/packages/59/17/012150e6a8e9071a9d976cfbf8ce8c381c00da6b718002c3a42e3f9cbfac/sumtypes-0.1a5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aef5b667ecee252d149d2a9aab7e0afb", "sha256": "bb57fa40a341fc9204ba7f03f181a5d3c0ab765f4ee517a6ba96d8311f4713e7" }, "downloads": -1, "filename": "sumtypes-0.1a5.tar.gz", "has_sig": false, "md5_digest": "aef5b667ecee252d149d2a9aab7e0afb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5345, "upload_time": "2019-02-07T23:29:04", "url": "https://files.pythonhosted.org/packages/8b/4a/01bd2b8bf675dca114fcc3a6e3900d28fbc468d8e1ecc5c00fb3fc953af4/sumtypes-0.1a5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6cab6c5fd3bb91f05cb5cb8523718b3d", "sha256": "148b45ba70b8b82c043e1a9346009b32cf13e03a1083919edf4fd76cb952a8af" }, "downloads": -1, "filename": "sumtypes-0.1a5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6cab6c5fd3bb91f05cb5cb8523718b3d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5747, "upload_time": "2019-02-07T23:29:02", "url": "https://files.pythonhosted.org/packages/59/17/012150e6a8e9071a9d976cfbf8ce8c381c00da6b718002c3a42e3f9cbfac/sumtypes-0.1a5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aef5b667ecee252d149d2a9aab7e0afb", "sha256": "bb57fa40a341fc9204ba7f03f181a5d3c0ab765f4ee517a6ba96d8311f4713e7" }, "downloads": -1, "filename": "sumtypes-0.1a5.tar.gz", "has_sig": false, "md5_digest": "aef5b667ecee252d149d2a9aab7e0afb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5345, "upload_time": "2019-02-07T23:29:04", "url": "https://files.pythonhosted.org/packages/8b/4a/01bd2b8bf675dca114fcc3a6e3900d28fbc468d8e1ecc5c00fb3fc953af4/sumtypes-0.1a5.tar.gz" } ] }