{ "info": { "author": "Tom Berry", "author_email": "tberry860@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "A simple syntax for piping in Python.\n\nCompare:\n\n.. code-block:: python\n\n from bookends import _\n from toolz.curried import map\n\n l = _| [3, 2, 1] | map(lambda n: n*2) | sorted |_ # [2, 4, 6]\n\nwith:\n\n.. code-block:: python\n\n l = sorted(map(lambda n: n*2, [3, 2, 1]))\n\n l = sorted([n*2 for n in [3, 2, 1]])\n\n l = []\n for n in [3, 2, 1]:\n l.append(n*2)\n l.sort()\n \nFor an extended comparison, see `example.py `_.\n\n\nTo install:\n\n.. code-block:: python\n\n pip install bookends\n\n\nTo use:\n\n.. code-block:: python\n\n from bookends import _\n\n\nFor similar tools, see:\n\n- `from fn import F `_\n- `from toolz import thread_first, thread_last `_, `pipe `_\n- `Clojure's -> and ->> `_\n- `Underscore's chain `_\n- Unix |\n\n\nNote: for multiline usage, wrap the expression in parens.\n\n.. code-block:: python\n\n import csv\n from StringIO import StringIO\n\n (_| '40,5,10\\n20,6,9\\n41,10,10\\n'\n | StringIO\n | csv.reader\n | sorted\n |_)\n\n # [['20', '6', '9'], ['40', '5', '10'], ['41', '10', '10']]\n \n\nWrap lone lambdas in parens as well.\n\n.. code-block:: python\n \n (_| ['addition', 'multiplication']\n | (lambda l: l + ['exponentiation', 'tetration'])\n | ', '.join\n |_)\n\n # 'addition, multiplication, exponentiation, tetration'\n\n\nYou can use partial or `curried `_ functions.\n\n.. code-block:: python\n \n from functools import partial\n from toolz.curried import drop\n\n (_| ['ca', 'tx', 'ny']\n | partial(map, lambda state: state.upper())\n | drop(1)\n | list\n |_)\n\n # ['TX', 'NY']\n\n\nAnd/or use `threading `_ syntax, by putting each function and its arguments into a tuple.\n\n.. code-block:: python\n \n from toolz import drop\n\n (_| ['ca', 'tx', 'ny']\n | (map, lambda state: state.upper())\n | (drop, 1)\n | list\n |_)\n\n # ['TX', 'NY']\n\n\nIf you don't like the underscore, import the bookend as B.\n\n.. code-block:: python\n \n from bookends import B\n\n (B| ['ca', 'tx', 'ny']\n | (map, lambda state: state.upper())\n | (drop, 1)\n | list\n |B)\n\n\nTo stop in the debugger before each function call, put a :code:`step` into the pipe.\n\n.. code-block:: python\n \n from bookends import step\n\n (_| [3, 2, 1]\n | (map, lambda x: x*2)\n | step # <==\n | sorted\n | sum\n |_)\n\n\nTo call off the stepping, drop in an :code:`endstep`.\n\n.. code-block:: python\n \n from bookends import step, endstep\n\n (_| [3, 2, 1]\n | (map, lambda x: x*2)\n | step # <==\n | sorted\n | endstep # <==\n | sum\n |_)\n\n\nTo print each function and its output, drop in a :code:`verbose`.\n\n.. code-block:: python\n \n from bookends import verbose\n\n (_| [3, 2, 1]\n | verbose # <==\n | (map, lambda x: x*2)\n | sorted\n | sum\n |_)\n\n\nYou can easily add these options while debugging by tacking on their first letter to the initial bookend.\n\n.. code-block:: python\n \n (_.sv| [3, 2, 1] # <== Turn on step and verbose (_.s, _.v, and _.vs work too).\n | (map, lambda x: x*2)\n | sorted\n | sum\n |_)\n\n\nDrop in a function that won't affect the operand by decorating it with passthrough.\n\n.. code-block:: python\n\n from bookends import passthrough\n\n @passthrough\n def log(operand):\n log.info('Operand was {}.'.format(operand))\n \n (_| [3, 2, 1]\n | (map, lambda x: x*2)\n | log # <==\n | sorted\n |_)\n\n\nPlays nice with `Kachayev's _ `_.\n\n.. code-block:: python\n \n from fn import _ as __\n\n _| [1, 2, 3] | __ + [4, 5] |_\n\n # [1, 2, 3, 4, 5]\n\n\nHere's a simplified version of the source:\n\n.. code-block:: python\n\n class Bookend():\n def __or__(self, operand):\n return Pipe(operand)\n\n\n class Pipe():\n def __init__(self, operand):\n self.operand = operand\n\n def __or__(self, f):\n if isinstance(f, Bookend):\n return self.operand\n else:\n self.operand = f(self.operand)\n return self\n\n\n _ = Bookend()\n\n\nContact: `@bzrry `_.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/berrytj/bookends", "keywords": "functional pipe", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "bookends", "package_url": "https://pypi.org/project/bookends/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/bookends/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/berrytj/bookends" }, "release_url": "https://pypi.org/project/bookends/0.0.5/", "requires_dist": null, "requires_python": null, "summary": "A simple piping syntax", "version": "0.0.5" }, "last_serial": 1190694, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "c6d65b6bacb81022711e6dd3310967e8", "sha256": "8e73da3cc08ccfbbe00a870837e7a4745e5fc3596c54e4ec433779c16e15944d" }, "downloads": -1, "filename": "bookends-0.0.1.tar.gz", "has_sig": false, "md5_digest": "c6d65b6bacb81022711e6dd3310967e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2321, "upload_time": "2014-08-02T22:44:38", "url": "https://files.pythonhosted.org/packages/7f/f5/33ed35b79f9df2f1ba07327cb02dda605c98d93e1278f08672cbe972420a/bookends-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "0ce4c55046709976b7e9283ebe21b185", "sha256": "105c2462ba5bbf64818d39bbd223ba05acb06ffff3abcb88d531ccf1bb366ee7" }, "downloads": -1, "filename": "bookends-0.0.2.tar.gz", "has_sig": false, "md5_digest": "0ce4c55046709976b7e9283ebe21b185", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2408, "upload_time": "2014-08-03T18:13:09", "url": "https://files.pythonhosted.org/packages/86/ae/5d0ff5fd6e35e221d5dcf8d36d341c9c778e2222dfe4862b3336877ba3d5/bookends-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "b10cd5162a1820d2b75fbb4ddbdfd6da", "sha256": "ac998423535b1bd063f8049d351a39302380082c0a8fac6867c697f92f3520dc" }, "downloads": -1, "filename": "bookends-0.0.3.tar.gz", "has_sig": false, "md5_digest": "b10cd5162a1820d2b75fbb4ddbdfd6da", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4771, "upload_time": "2014-08-13T20:34:29", "url": "https://files.pythonhosted.org/packages/f5/6f/3698bebbf3a9e39e4bc80cfa82fe726b6c7d6d92acbb32753b3e08fba4f2/bookends-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "52ad2e20bd883cac5901825858ceb6df", "sha256": "0fcf2390a432e8407369bb206394e423db185df0437a7f92975ed2e3716b0c12" }, "downloads": -1, "filename": "bookends-0.0.4.tar.gz", "has_sig": false, "md5_digest": "52ad2e20bd883cac5901825858ceb6df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4787, "upload_time": "2014-08-13T20:41:18", "url": "https://files.pythonhosted.org/packages/63/81/fa6353ada0629f78081b1904df6607901f58aad9267b8e5a2364aea4c840/bookends-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "8ca5bd1b0db6c85cadb2ca947b333189", "sha256": "bd74153e6a55714a00d007e0872cbc9fb4781de648e4acb0812baa10e23bbcd5" }, "downloads": -1, "filename": "bookends-0.0.5.tar.gz", "has_sig": false, "md5_digest": "8ca5bd1b0db6c85cadb2ca947b333189", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4779, "upload_time": "2014-08-14T17:25:19", "url": "https://files.pythonhosted.org/packages/e1/76/12863e1aee582ac25704d3f95bcdbb125d70eb7d4504cde0f6fa075ae621/bookends-0.0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8ca5bd1b0db6c85cadb2ca947b333189", "sha256": "bd74153e6a55714a00d007e0872cbc9fb4781de648e4acb0812baa10e23bbcd5" }, "downloads": -1, "filename": "bookends-0.0.5.tar.gz", "has_sig": false, "md5_digest": "8ca5bd1b0db6c85cadb2ca947b333189", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4779, "upload_time": "2014-08-14T17:25:19", "url": "https://files.pythonhosted.org/packages/e1/76/12863e1aee582ac25704d3f95bcdbb125d70eb7d4504cde0f6fa075ae621/bookends-0.0.5.tar.gz" } ] }