{ "info": { "author": "Eran Kampf", "author_email": "eran@ekampf.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4" ], "description": "===============================\nPyMaybe\n===============================\n\n.. image:: https://travis-ci.org/ekampf/pymaybe.svg?branch=master\n :target: https://travis-ci.org/ekampf/pymaybe\n\n.. image:: https://coveralls.io/repos/ekampf/pymaybe/badge.svg?branch=master&service=github\n :target: https://coveralls.io/github/ekampf/pymaybe?branch=master\n\n.. image:: https://img.shields.io/pypi/v/pymaybe.svg\n :target: https://pypi.python.org/pypi/pymaybe\n\nA Python implementation of the Maybe pattern.\n\nInstallation\n------------\n\n::\n\n pip install pymaybe\n\nGetting Started\n---------------\n\n::\n\n from pymaybe import maybe\n first_name = maybe(deep_hash)['account']['user_profile']['first_name'].or_else(\"\")\n\nDocumentation\n-------------\nMaybe monad is a programming pattern that allows to treat None values that same way as non-none values.\nThis is done by wrapping the value, which may or may not be None to, a wrapper class.\n\nThe implementation includes two classes: *Maybe* and *Something*.\n*Something* represents a value while *Nothing* represents a None value.\nThere's also a method *maybe* which wraps a regular value and and returns *Something* or *Nothing* instance.\n\n::\n\n >>> maybe(\"I'm a value\")\n \"I'm a value\"\n\n >>> maybe(None);\n None\n\nBoth *Something* and *Nothing* implement 4 methods allowing you to test their real value: *is_some*, *is_none*, *get* and *or_else*\n\n::\n\n >>> maybe(\"I'm a value\").is_some()\n True\n\n >>> maybe(\"I'm a value\").is_none()\n False\n\n >>> maybe(None).is_some()\n False\n\n >>> maybe(None).is_none()\n True\n\n >>> maybe(\"I'm a value\").get()\n \"I'm a value\"\n\n >>> maybe(\"I'm a value\").or_else(lambda: \"No value\")\n \"I'm a value\"\n\n >>> maybe(None).get()\n Traceback (most recent call last):\n ...\n Exception: No such element\n\n >>> maybe(None).or_else(lambda: \"value\")\n 'value'\n\n >>> maybe(None).or_else(\"value\")\n 'value'\n\nIn addition, *Something* and *Nothing* implement the Python magic methods allowing you to treat them as dictionaries:\n\n::\n >>> nested_dict = maybe(nested_dict)\n >>> nested_dict['store']['name']\n 'MyStore'\n\n >>> nested_dict['store']['address']\n None\n\n >>> nested_dict['store']['address']['street'].or_else('No Address Specified')\n 'No Address Specified'\n\nAll other method calls on *Something* are forwarded to its real *value*:\n\n::\n\n >>> maybe('VALUE').lower()\n 'value'\n\n >>> maybe(None).invalid().method().or_else('unknwon')\n 'unknwon'\n\nExamples & Use Cases\n--------------------\n\nThe Maybe pattern helps you avoid nasty try..except blocks.\nConsider the following code:\n\n::\n try:\n url = rss.load_feeds()[0].url.domain\n except (TypeError, IndexError, KeyError, AttributeError):\n url = \"planetpython.org\"\n\nWith Maybe you could simply do:\n\n::\n\n url = maybe(rss).load_feeds()[0]['url'].domain.or_else(\"planetpython.org\")\n\nGetting the current logged in user's name.\nWithout maybe:\n\n::\n\n def get_user_zipcode():\n address = getattr(request.user, 'address', None)\n if address:\n return getattr(address, 'zipcode', '')\n\n return ''\n\nWith maybe:\n\n::\n\n def get_user_zipcode():\n return maybe(request.user).address.zipcode.or_else('')\n\nFurther Reading\n---------------\n\n* `Option (Scala) `_\n* `Maybe (Java) `_\n* `Maybe pattern (Python recipe) `_\n* `Data.Maybe (Haskell) `_\n* `Maybe (Ruby) `_\n\nCopyright and License\n---------------------\nCopyright 2015 - `Eran Kampf `_\n\n* Free software: BSD license\n* Documentation: https://pymaybe.readthedocs.org.\n* Code is hosted on `GitHub `_\n\n\n\n\nHistory\n-------\n\n0.1.0 (2015-01-11)\n---------------------\n\n* First release on PyPI.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ekampf/pymaybe", "keywords": "pymaybe", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "pymaybe", "package_url": "https://pypi.org/project/pymaybe/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pymaybe/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ekampf/pymaybe" }, "release_url": "https://pypi.org/project/pymaybe/0.1.6/", "requires_dist": null, "requires_python": null, "summary": "A Python implementation of the Maybe pattern.", "version": "0.1.6" }, "last_serial": 1742855, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "599fc51cfdc06c26cd6fa6da00b40147", "sha256": "4696150c32b363976e1228990859c1288c3c2152ce19442c94c3c86c03766e03" }, "downloads": -1, "filename": "pymaybe-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "599fc51cfdc06c26cd6fa6da00b40147", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 4785, "upload_time": "2015-07-13T06:31:39", "url": "https://files.pythonhosted.org/packages/9e/d6/6b140c97b87a5fd589b98e51d62f751c79c2c3f07814a92222d0a75e58b1/pymaybe-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0e217f3d812ffd184371cf4847315d7e", "sha256": "c0b5e6bc1e816c32e10a185600cf2a695202606c2089df5a1ff4d45f31f33c0b" }, "downloads": -1, "filename": "pymaybe-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0e217f3d812ffd184371cf4847315d7e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13124, "upload_time": "2015-07-13T06:31:35", "url": "https://files.pythonhosted.org/packages/6c/f8/65a3165e98e30e8122a5c7a0ac9bce945783d52f92cf9604b8e71f65e4e2/pymaybe-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "bfcd476ab697630701eb0884dd3b84c5", "sha256": "76e22c29dd162190d35d12660d47a8744b0ee7def02c13f357b1957332d313db" }, "downloads": -1, "filename": "pymaybe-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "bfcd476ab697630701eb0884dd3b84c5", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7425, "upload_time": "2015-07-13T08:16:06", "url": "https://files.pythonhosted.org/packages/19/f4/b78d1d20ac8b7d4afebae7a816d0f26a70ecc1e3162b7cdfaf1624b72e99/pymaybe-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1309fcda5ef4e464883ae71d1697b349", "sha256": "de358cd6ef7385eac86a664fda5b8d5401ff8188f9d081d9aad2cc96229a3dbd" }, "downloads": -1, "filename": "pymaybe-0.1.1.tar.gz", "has_sig": false, "md5_digest": "1309fcda5ef4e464883ae71d1697b349", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14781, "upload_time": "2015-07-13T08:16:01", "url": "https://files.pythonhosted.org/packages/25/46/052e1aa436b587343562097eafc77df4079e5ec6b10ff30eaa60d66cf24e/pymaybe-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "873cfd4ffb1f76df3d81735b461d7f58", "sha256": "ad699b40f6914fb4f8be944554e02ae108018e348f65f91c844944e158c6c1c6" }, "downloads": -1, "filename": "pymaybe-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "873cfd4ffb1f76df3d81735b461d7f58", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7547, "upload_time": "2015-07-14T06:10:51", "url": "https://files.pythonhosted.org/packages/26/97/1775f6cb2854725bf15164034e9c305604f30a57c2ca806c1fe402ca0adc/pymaybe-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c89cdb706f9119ae4a55f889ec715610", "sha256": "31b7786ea72908bcf5815804087b4f54bb1e5ece9eb3880ec64513c5df8bcce3" }, "downloads": -1, "filename": "pymaybe-0.1.2.tar.gz", "has_sig": false, "md5_digest": "c89cdb706f9119ae4a55f889ec715610", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15527, "upload_time": "2015-07-14T06:10:46", "url": "https://files.pythonhosted.org/packages/ba/95/cd8a485613e880ff9f548e532eca2e966ca9faa2caf8b450d3122cb43d75/pymaybe-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "dbbd4dd16c471a9c0d280fd343c54145", "sha256": "ce9c286a4aaf9c3f08711b71d0cf5a920c77ba448c7848a327339e014ae37486" }, "downloads": -1, "filename": "pymaybe-0.1.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dbbd4dd16c471a9c0d280fd343c54145", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7546, "upload_time": "2015-07-14T06:11:29", "url": "https://files.pythonhosted.org/packages/5c/60/788edf8862064b2086516c6708fb9c8c75eba07efff6075c518d6719ca55/pymaybe-0.1.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "94e3e69fb8860216a31b684a88ff242b", "sha256": "3c46509b849d550e99049545657f4efa99cf8a399dea4f8a9e44e9e4296da8a9" }, "downloads": -1, "filename": "pymaybe-0.1.3.tar.gz", "has_sig": false, "md5_digest": "94e3e69fb8860216a31b684a88ff242b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15527, "upload_time": "2015-07-14T06:11:25", "url": "https://files.pythonhosted.org/packages/e9/3a/338b78764e5d2f1b324e087eae8a983f4cca57ee85d776240a2050266e66/pymaybe-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "d23fbe9a500bf2e28bbc8f23c3fa2155", "sha256": "50a5f7b251aed0201febec8f56b437bab41240f74d3cee6d2936a816de554f49" }, "downloads": -1, "filename": "pymaybe-0.1.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d23fbe9a500bf2e28bbc8f23c3fa2155", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7543, "upload_time": "2015-07-31T01:08:39", "url": "https://files.pythonhosted.org/packages/95/c5/9f1c9eb3777da6307ba5d59532002fc6b3e039a48d918a81132444ae2098/pymaybe-0.1.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "861922633cc58a4a5a00a053e7b0b2d3", "sha256": "96a122c96dfb55e90753e981ff73befe9ff52e27128ab71aa30be9987defedae" }, "downloads": -1, "filename": "pymaybe-0.1.4.tar.gz", "has_sig": false, "md5_digest": "861922633cc58a4a5a00a053e7b0b2d3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16192, "upload_time": "2015-07-31T01:08:36", "url": "https://files.pythonhosted.org/packages/a8/88/e9513d612f962f96468593276fb945c753754006fbd0e78bd8c379b80385/pymaybe-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "a597f496b437bc269db736ec6aba4bb0", "sha256": "581f9fa5d9ae6176ef4cf40c1ecbab4eea274e8cdd554484957750b31e55814c" }, "downloads": -1, "filename": "pymaybe-0.1.5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a597f496b437bc269db736ec6aba4bb0", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7633, "upload_time": "2015-07-31T06:29:53", "url": "https://files.pythonhosted.org/packages/bb/2a/4e07b4813f67ff615b0954885196b82b5c02eff2c7a6af2b55b6011196d9/pymaybe-0.1.5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ccd225bc71e63cdcfcb93c5c7ef1dc7b", "sha256": "d01d183fa656ca06ccb5be05396d000be12efc8ea9f479446e39adea4855552d" }, "downloads": -1, "filename": "pymaybe-0.1.5.tar.gz", "has_sig": false, "md5_digest": "ccd225bc71e63cdcfcb93c5c7ef1dc7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16458, "upload_time": "2015-07-31T06:29:48", "url": "https://files.pythonhosted.org/packages/00/41/4fe3ee0ba2ad2350f5352593b9f94b5b1003585d9cc3999c2aeab7a4cb56/pymaybe-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "5e37221b3280109ea436700a996ec747", "sha256": "01d0f71b98e1c155ecfecd9db44ce49f37ae374b5cb8f1d27c0ee00c3d7aa4dd" }, "downloads": -1, "filename": "pymaybe-0.1.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5e37221b3280109ea436700a996ec747", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7826, "upload_time": "2015-09-28T21:23:53", "url": "https://files.pythonhosted.org/packages/83/f8/3bd91975bfbed25e453589d079cbf4f8f0b44a9cf6a82bfebbd69506b060/pymaybe-0.1.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30c7a1af361f327abb0e58191072ae01", "sha256": "77ed1602e1b9e8b05dccd0d84891ede4ee2004728170e52af7f9c08d4c62378c" }, "downloads": -1, "filename": "pymaybe-0.1.6.tar.gz", "has_sig": false, "md5_digest": "30c7a1af361f327abb0e58191072ae01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16670, "upload_time": "2015-09-28T21:23:47", "url": "https://files.pythonhosted.org/packages/fe/86/0bbefee601f7f5ce5fdd11ee59cbae36ce9cb48b96c44f960f38cbfe6d0a/pymaybe-0.1.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5e37221b3280109ea436700a996ec747", "sha256": "01d0f71b98e1c155ecfecd9db44ce49f37ae374b5cb8f1d27c0ee00c3d7aa4dd" }, "downloads": -1, "filename": "pymaybe-0.1.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5e37221b3280109ea436700a996ec747", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7826, "upload_time": "2015-09-28T21:23:53", "url": "https://files.pythonhosted.org/packages/83/f8/3bd91975bfbed25e453589d079cbf4f8f0b44a9cf6a82bfebbd69506b060/pymaybe-0.1.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "30c7a1af361f327abb0e58191072ae01", "sha256": "77ed1602e1b9e8b05dccd0d84891ede4ee2004728170e52af7f9c08d4c62378c" }, "downloads": -1, "filename": "pymaybe-0.1.6.tar.gz", "has_sig": false, "md5_digest": "30c7a1af361f327abb0e58191072ae01", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16670, "upload_time": "2015-09-28T21:23:47", "url": "https://files.pythonhosted.org/packages/fe/86/0bbefee601f7f5ce5fdd11ee59cbae36ce9cb48b96c44f960f38cbfe6d0a/pymaybe-0.1.6.tar.gz" } ] }