{ "info": { "author": "Scott Sanderson", "author_email": "scott.b.sanderson90@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "==============\n``switchcase``\n==============\n\n``switchcase`` implements a simple Switch-Case construct in Pure Python.\n\nUnder the hood, the ``switch`` function works by simply returning a length-1\nlist containing a matching function. The entire implementation is 3 lines long:\n\n.. code:: python\n\n from operator import eq\n def switch(value, comp=eq):\n return [lambda match: comp(match, value)]\n\n\nBasic Usage\n-----------\n\n.. code-block:: python\n\n >>> from switchcase import switch\n >>> def func(x):\n ... for case in switch(x):\n ... if case(0):\n ... print(\"x was 0\")\n ... break\n ... if case(1):\n ... print(\"x was 1\")\n ... break\n ... else:\n ... print(\"x was unmatched\")\n >>> func(0)\n \"x was 0\"\n >>> func(1)\n \"x was 1\"\n >>> func(2)\n \"x was unmatched\"\n\n\nCustom Comparisons\n------------------\n\nBy default, ``switch`` uses ``operator.eq`` to compare the value passed to\n``switch`` and the values subsequently passed to ``case``. You can override\nthis behavior by passing a comparator function to ``switch`` as a second\nargument.\n\n\n.. code-block:: python\n\n >>> import re\n >>> from switchcase import switch\n >>> def f(x):\n ... out = []\n ... for case in switch(x, comp=re.match):\n ... if case(\"foo_bar\"):\n ... out.append(0)\n ... break\n ... if case(\"foo_.*\"):\n ... out.append(1)\n ... if case(\".*_bar\"):\n ... out.append(2)\n ... return out\n >>> f(\"foo_bar\")\n [0]\n >>> f(\"foo_notbar\")\n [1]\n >>> f(\"notfoo_bar\")\n [2]\n >>> f(\"foo____bar\")\n [1, 2]", "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/ssanderson/switchcase", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "switchcase", "package_url": "https://pypi.org/project/switchcase/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/switchcase/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ssanderson/switchcase" }, "release_url": "https://pypi.org/project/switchcase/1.0/", "requires_dist": null, "requires_python": null, "summary": "Switch-Case in pure Python", "version": "1.0" }, "last_serial": 1682803, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "0e1424a4a4d7f5c79c1694c5ce200c22", "sha256": "4170300a2e69611cff996e508fb3a2d3caff257f44f70c987dbfe3500b722e72" }, "downloads": -1, "filename": "switchcase-1.0.tar.gz", "has_sig": false, "md5_digest": "0e1424a4a4d7f5c79c1694c5ce200c22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2246, "upload_time": "2015-08-18T18:06:15", "url": "https://files.pythonhosted.org/packages/01/08/44a3d89b53d8d43266126584821bc08e0b3d0e95a2025fed3ec3bd7ab5b1/switchcase-1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0e1424a4a4d7f5c79c1694c5ce200c22", "sha256": "4170300a2e69611cff996e508fb3a2d3caff257f44f70c987dbfe3500b722e72" }, "downloads": -1, "filename": "switchcase-1.0.tar.gz", "has_sig": false, "md5_digest": "0e1424a4a4d7f5c79c1694c5ce200c22", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2246, "upload_time": "2015-08-18T18:06:15", "url": "https://files.pythonhosted.org/packages/01/08/44a3d89b53d8d43266126584821bc08e0b3d0e95a2025fed3ec3bd7ab5b1/switchcase-1.0.tar.gz" } ] }