{ "info": { "author": "Brett Beatty", "author_email": "brettbeatty@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Matchstick: pattern matching in Python\n======================================\n\n.. image:: https://img.shields.io/circleci/project/github/brettbeatty/hand_grenade.svg\n :target: https://circleci.com/gh/brettbeatty/hand_grenade\n\n.. image:: https://img.shields.io/github/license/brettbeatty/hand_grenade.svg\n :target: https://github.com/brettbeatty/hand_grenade/blob/master/LICENSE\n\n.. image:: https://img.shields.io/codecov/c/github/brettbeatty/hand_grenade.svg\n :target: https://codecov.io/gh/brettbeatty/hand_grenade\n\n.. image:: https://img.shields.io/pypi/v/hand_grenade.svg\n :target: https://pypi.org/project/hand_grenade/\n\nMatchstick provides a decorator that allows for the overloading of Python functions.\n\n.. code-block:: python\n\n >>> from matchstick import when\n >>> @when('x >= 0')\n ... def f(x):\n ... return x\n ...\n >>> @when('x < 0')\n ... def f(x):\n ... return -x\n ...\n >>> f(3)\n 3\n >>> f(-2)\n 2\n >>> f('a')\n 'a'\n\nBasic Use\n---------\nConditions\n^^^^^^^^^^\nThe match decorator takes a condition as a string. When the decorated function gets called, overloaded functions (grouped by module and qualified name) are checked in the order they are defined. Each condition is evaluated with the arguments passed to the function (including default parameter values, where applicable). If the condition evaluates truthy, the corresponding function is called. If the condition evaluates falsy or raises an exception, the corresponding function is passed over.\n\n.. code-block:: python\n\n >>> @when('x[2] == 5')\n ... def f(x):\n ... return sum(x)\n ...\n >>> @when('len(x) > 3')\n ... def f(x):\n ... return x[3:]\n ...\n >>> @when('True')\n ... def f(x):\n ... return x\n ...\n >>> f([3, 4, 5, 6])\n 18\n >>> f([0, 1, 2, 3])\n [3]\n >>> f('abcd')\n 'd'\n >>> f({})\n {}\n\nNoMatchException\n^^^^^^^^^^^^^^^^\nIf none of the conditions for a function evaluate truthy, a *matchstick.NoMatchException* is raised.\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/brettbeatty/matchstick", "keywords": "pattern", "license": "", "maintainer": "", "maintainer_email": "", "name": "matchstick", "package_url": "https://pypi.org/project/matchstick/", "platform": "", "project_url": "https://pypi.org/project/matchstick/", "project_urls": { "Homepage": "https://github.com/brettbeatty/matchstick" }, "release_url": "https://pypi.org/project/matchstick/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "Pattern matching in Python", "version": "0.1.1" }, "last_serial": 3423961, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "66ea53e09581d5d0ea997e00c5c7b289", "sha256": "c5c6244b7ece1c8321726fbb2b6b50a7d11208189c1b1f9d7e304588c61514bc" }, "downloads": -1, "filename": "matchstick-0.1.tar.gz", "has_sig": false, "md5_digest": "66ea53e09581d5d0ea997e00c5c7b289", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1993, "upload_time": "2017-10-15T03:19:04", "url": "https://files.pythonhosted.org/packages/41/42/0ecc087895452f84e13f74756dace4cf5e28a8521ef99f227f9d6904e8ad/matchstick-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "472c19c785f23c82e66f5942d7ffda23", "sha256": "16f114c166569b85f8819ae6e8daf73e8469865760c86d45fb2ad5dae12be008" }, "downloads": -1, "filename": "matchstick-0.1.1.tar.gz", "has_sig": false, "md5_digest": "472c19c785f23c82e66f5942d7ffda23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3821, "upload_time": "2017-12-18T01:29:25", "url": "https://files.pythonhosted.org/packages/a7/c1/203df211fb6334a02536bd1b521c45af5b5564dcf40b766a84b7e39fee91/matchstick-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "472c19c785f23c82e66f5942d7ffda23", "sha256": "16f114c166569b85f8819ae6e8daf73e8469865760c86d45fb2ad5dae12be008" }, "downloads": -1, "filename": "matchstick-0.1.1.tar.gz", "has_sig": false, "md5_digest": "472c19c785f23c82e66f5942d7ffda23", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3821, "upload_time": "2017-12-18T01:29:25", "url": "https://files.pythonhosted.org/packages/a7/c1/203df211fb6334a02536bd1b521c45af5b5564dcf40b766a84b7e39fee91/matchstick-0.1.1.tar.gz" } ] }