{ "info": { "author": "Brett Beatty", "author_email": "brettbeatty@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "lead_pipe\n=========\n\n.. image:: https://img.shields.io/circleci/project/github/brettbeatty/lead_pipe.svg\n :target: https://circleci.com/gh/brettbeatty/lead_pipe\n\n.. image:: https://img.shields.io/github/license/brettbeatty/lead_pipe.svg\n :target: https://github.com/brettbeatty/lead_pipe/blob/master/LICENSE\n\n.. image:: https://img.shields.io/codecov/c/github/brettbeatty/lead_pipe.svg\n :target: https://codecov.io/gh/brettbeatty/lead_pipe\n\n.. image:: https://img.shields.io/pypi/v/lead_pipe.svg\n :target: https://pypi.org/project/lead_pipe/\n\nLead Pipe allows values to be piped from one function to the next without nesting the calls. For example, the following blocks of code are equivalent.\n\n.. code-block:: python\n\n a = foo(bar(baz(8, 2), a=3), 4)\n\n.. code-block:: python\n\n from lead_pipe import Pipe\n a = ~Pipe(8)(baz, 2)(bar, a=3)(foo, 4)\n\nBasic Use\n---------\nCreating a Pipe\n^^^^^^^^^^^^^^^\nPipelines begin with a base value passed to the Pipe constructor.\n\n.. code-block:: python\n\n >>> from lead_pipe import Pipe\n >>> Pipe(3)\n Pipe(3)\n >>> Pipe('a')\n Pipe('a')\n\nPiping Results\n^^^^^^^^^^^^^^\nEach instance of Pipe is callable and takes any number of arguments (at least one). The first argument is a function that gets called with the pipeline's value followed by the additional arguments and keyword arguments, if any.\n\n.. code-block:: python\n\n >>> Pipe(3)(lambda x: x + 0.5)(lambda x: x ** 2)(int)('{} - {x} + {}'.format, 1, x=8)(eval)\n Pipe(5)\n\nObtaining Result\n^^^^^^^^^^^^^^^^\nOnce your pipeline is finished, you can retrieve the result with the tilde (~) operator or through the pipe's 'value' attribute.\n\n.. code-block:: python\n\n >>> ~Pipe(11)\n 11\n >>> Pipe('foo').value\n 'foo'\n >>> ~Pipe(2)(pow, 3)(str)\n '8'\n\nAdvanced Features\n-----------------\nIntermediate Pipes\n^^^^^^^^^^^^^^^^^^\nSince each step along the pipeline is its own instance of Pipe, an intermediate pipe can be saved to pipe to multiple functions.\n\n.. code-block:: python\n\n >>> p = Pipe(4)(range)(zip, range(2, 6))\n >>> p\n Pipe([(0, 2), (1, 3), (2, 4), (3, 5)])\n >>> p(dict).value[2]\n 4\n >>> ~p(lambda x: x[1][1])\n 3\n\nApply\n^^^^^\nSometimes a function may return another function rather than a value to be piped to another function. Apply is a helper function that continues the pipeline with the function returned.\n\n.. code-block:: python\n\n >>> from lead_pipe import apply\n >>> ~Pipe('{} foo{a} {}'.format)(apply, 'bar', 'baz', a=3)\n 'bar foo3 baz'\n\nReflect\n^^^^^^^\nSometimes one may want to call a member function of a value in the pipeline. One way would be to pipe the value to getattr then to apply, but the reflect function is the combination of the two.\n\n.. code-block:: python\n\n >>> from lead_pipe import reflect\n >>> ~Pipe({'a': 1, 'b': 2})(reflect, 'get', 'a')\n 1\n\nIn this specific example, one could pipe the dictionary to dict.get, but reflect is more general.\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/lead_pipe", "keywords": "piping", "license": "", "maintainer": "", "maintainer_email": "", "name": "lead_pipe", "package_url": "https://pypi.org/project/lead_pipe/", "platform": "", "project_url": "https://pypi.org/project/lead_pipe/", "project_urls": { "Homepage": "https://github.com/brettbeatty/lead_pipe" }, "release_url": "https://pypi.org/project/lead_pipe/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "piping between functions in Python", "version": "0.2.1" }, "last_serial": 3423994, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "fb9ebd31527472ba50e3bc4ae8fa463f", "sha256": "21aecc51fad0064f9ff21532e8c24d5fb56ea1f2303e56e9c79cd044213ff29f" }, "downloads": -1, "filename": "lead_pipe-0.1.tar.gz", "has_sig": false, "md5_digest": "fb9ebd31527472ba50e3bc4ae8fa463f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1286, "upload_time": "2017-09-17T02:54:03", "url": "https://files.pythonhosted.org/packages/f6/1e/2f363c1aa9a936ac7e75a23a7c143d3c3ec8679cd8fa1f32c1f14058f2f3/lead_pipe-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "f07a485f658248647641af30b087a379", "sha256": "72232b2840088926cd2e589ad345d417fc65d21fae854eebd820070c7caa5db6" }, "downloads": -1, "filename": "lead_pipe-0.2.tar.gz", "has_sig": false, "md5_digest": "f07a485f658248647641af30b087a379", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1290, "upload_time": "2017-10-12T18:08:07", "url": "https://files.pythonhosted.org/packages/9e/19/8a41b9a9958214312560e09f90d696c24e1972d05ff6b81120d76e650ba4/lead_pipe-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "6a686903eab30c37e1eb9603534b27fe", "sha256": "38c07bf0d62fd10a2ccbe376ceb3d1882c155034ae48af80770d6b58ee1da4b3" }, "downloads": -1, "filename": "lead_pipe-0.2.1.tar.gz", "has_sig": false, "md5_digest": "6a686903eab30c37e1eb9603534b27fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3338, "upload_time": "2017-12-18T02:15:20", "url": "https://files.pythonhosted.org/packages/28/b7/ddcb763e05e753510551d755d826fa542b65e9e474b058ce338105f771b6/lead_pipe-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6a686903eab30c37e1eb9603534b27fe", "sha256": "38c07bf0d62fd10a2ccbe376ceb3d1882c155034ae48af80770d6b58ee1da4b3" }, "downloads": -1, "filename": "lead_pipe-0.2.1.tar.gz", "has_sig": false, "md5_digest": "6a686903eab30c37e1eb9603534b27fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3338, "upload_time": "2017-12-18T02:15:20", "url": "https://files.pythonhosted.org/packages/28/b7/ddcb763e05e753510551d755d826fa542b65e9e474b058ce338105f771b6/lead_pipe-0.2.1.tar.gz" } ] }