gentools


Namegentools JSON
Version 1.2.2 PyPI version JSON
download
home_pagehttps://github.com/ariebovenberg/gentools
SummaryTools for generators, generator functions, and generator-based coroutines
upload_time2024-01-29 06:43:32
maintainer
docs_urlNone
authorArie Bovenberg
requires_python>=3.8.1,<4.0.0
licenseMIT
keywords generators itertools coroutines
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Gentools
========

.. image:: https://img.shields.io/pypi/v/gentools.svg?style=flat-square
    :target: https://pypi.python.org/pypi/gentools

.. image:: https://img.shields.io/pypi/l/gentools.svg?style=flat-square
    :target: https://pypi.python.org/pypi/gentools

.. image:: https://img.shields.io/pypi/pyversions/gentools.svg?style=flat-square
    :target: https://pypi.python.org/pypi/gentools

.. image::  https://img.shields.io/github/actions/workflow/status/ariebovenberg/gentools/tests.yml?branch=main&style=flat-square
   :target: https://github.com/ariebovenberg/gentools

.. image:: https://img.shields.io/codecov/c/github/ariebovenberg/gentools.svg?style=flat-square
    :target: https://coveralls.io/github/ariebovenberg/gentools?branch=main

.. image:: https://img.shields.io/readthedocs/gentools.svg?style=flat-square
    :target: http://gentools.readthedocs.io/en/latest/?badge=latest


Tools for generators, generator functions, and generator-based coroutines.

Key features:

* Create reusable generators
* Compose generators
* Build python 2/3-compatible generators (``gentools`` version <1.2 only)

Installation
------------

.. code-block:: bash

   pip install gentools

Examples
--------

- Make generator functions reusable:

.. code-block:: python

   >>> @reusable
   ... def countdown(value, step):
   ...     while value > 0:
   ...         yield value
   ...         value -= step

   >>> from_3 = countdown(3, step=1)
   >>> list(from_3)
   [3, 2, 1]
   >>> list(from_3)
   [3, 2, 1]
   >>> isinstance(from_3, countdown)  # generator func is wrapped in a class
   True
   >>> from_3.step  # attribute access to arguments
   1
   >>> from_3.replace(value=5)  # create new instance with replaced fields
   countdown(value=5, step=1)  # descriptive repr()

- map a generator's ``yield``, ``send``, and ``return`` values:

.. code-block:: python

   >>> @map_return('final value: {}'.format)
   ... @map_send(int)
   ... @map_yield('the current max is: {}'.format)
   ... def my_max(value):
   ...     while value < 100:
   ...         newvalue = yield value
   ...         if newvalue > value:
   ...             value = newvalue
   ...     return value

   >>> gen = my_max(5)
   >>> next(gen)
   'the current max is: 5'
   >>> gen.send(11.3)
   'the current max is: 11'
   >>> gen.send(104)
   StopIteration('final value: 104')

- relay a generator's yield/send interactions through another generator:

.. code-block:: python

   >>> def try_until_positive(outvalue):
   ...     value = yield outvalue
   ...     while value < 0:
   ...         value = yield 'not positive, try again'
   ...     return value

   >>> @relay(try_until_positive)
   ... def my_max(value):
   ...     while value < 100:
   ...         newvalue = yield value
   ...         if newvalue > value:
   ...             value = newvalue
   ...     return value

   >>> gen = my_max(5)
   >>> next(gen)
   5
   >>> gen.send(-4)
   'not positive, try again'
   >>> gen.send(-1)
   'not positive, try again'
   >>> gen.send(8)
   8
   >>> gen.send(104)
   StopIteration(104)

- make python 2/3 compatible generators with ``return``. 
  (`gentools` version <1.2 only)

.. code-block:: python

   >>> @py2_compatible
   ... def my_max(value):
   ...     while value < 100:
   ...         newvalue = yield value
   ...         if newvalue > value:
   ...             value = newvalue
   ...     return_(value)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ariebovenberg/gentools",
    "name": "gentools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0.0",
    "maintainer_email": "",
    "keywords": "generators,itertools,coroutines",
    "author": "Arie Bovenberg",
    "author_email": "a.c.bovenberg@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/21/4d/68ba01cf9e6da4d024c13684d97206346e9ba11ad470516104e1cd13d857/gentools-1.2.2.tar.gz",
    "platform": null,
    "description": "Gentools\n========\n\n.. image:: https://img.shields.io/pypi/v/gentools.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/gentools\n\n.. image:: https://img.shields.io/pypi/l/gentools.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/gentools\n\n.. image:: https://img.shields.io/pypi/pyversions/gentools.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/gentools\n\n.. image::  https://img.shields.io/github/actions/workflow/status/ariebovenberg/gentools/tests.yml?branch=main&style=flat-square\n   :target: https://github.com/ariebovenberg/gentools\n\n.. image:: https://img.shields.io/codecov/c/github/ariebovenberg/gentools.svg?style=flat-square\n    :target: https://coveralls.io/github/ariebovenberg/gentools?branch=main\n\n.. image:: https://img.shields.io/readthedocs/gentools.svg?style=flat-square\n    :target: http://gentools.readthedocs.io/en/latest/?badge=latest\n\n\nTools for generators, generator functions, and generator-based coroutines.\n\nKey features:\n\n* Create reusable generators\n* Compose generators\n* Build python 2/3-compatible generators (``gentools`` version <1.2 only)\n\nInstallation\n------------\n\n.. code-block:: bash\n\n   pip install gentools\n\nExamples\n--------\n\n- Make generator functions reusable:\n\n.. code-block:: python\n\n   >>> @reusable\n   ... def countdown(value, step):\n   ...     while value > 0:\n   ...         yield value\n   ...         value -= step\n\n   >>> from_3 = countdown(3, step=1)\n   >>> list(from_3)\n   [3, 2, 1]\n   >>> list(from_3)\n   [3, 2, 1]\n   >>> isinstance(from_3, countdown)  # generator func is wrapped in a class\n   True\n   >>> from_3.step  # attribute access to arguments\n   1\n   >>> from_3.replace(value=5)  # create new instance with replaced fields\n   countdown(value=5, step=1)  # descriptive repr()\n\n- map a generator's ``yield``, ``send``, and ``return`` values:\n\n.. code-block:: python\n\n   >>> @map_return('final value: {}'.format)\n   ... @map_send(int)\n   ... @map_yield('the current max is: {}'.format)\n   ... def my_max(value):\n   ...     while value < 100:\n   ...         newvalue = yield value\n   ...         if newvalue > value:\n   ...             value = newvalue\n   ...     return value\n\n   >>> gen = my_max(5)\n   >>> next(gen)\n   'the current max is: 5'\n   >>> gen.send(11.3)\n   'the current max is: 11'\n   >>> gen.send(104)\n   StopIteration('final value: 104')\n\n- relay a generator's yield/send interactions through another generator:\n\n.. code-block:: python\n\n   >>> def try_until_positive(outvalue):\n   ...     value = yield outvalue\n   ...     while value < 0:\n   ...         value = yield 'not positive, try again'\n   ...     return value\n\n   >>> @relay(try_until_positive)\n   ... def my_max(value):\n   ...     while value < 100:\n   ...         newvalue = yield value\n   ...         if newvalue > value:\n   ...             value = newvalue\n   ...     return value\n\n   >>> gen = my_max(5)\n   >>> next(gen)\n   5\n   >>> gen.send(-4)\n   'not positive, try again'\n   >>> gen.send(-1)\n   'not positive, try again'\n   >>> gen.send(8)\n   8\n   >>> gen.send(104)\n   StopIteration(104)\n\n- make python 2/3 compatible generators with ``return``. \n  (`gentools` version <1.2 only)\n\n.. code-block:: python\n\n   >>> @py2_compatible\n   ... def my_max(value):\n   ...     while value < 100:\n   ...         newvalue = yield value\n   ...         if newvalue > value:\n   ...             value = newvalue\n   ...     return_(value)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tools for generators, generator functions, and generator-based coroutines",
    "version": "1.2.2",
    "project_urls": {
        "Homepage": "https://github.com/ariebovenberg/gentools",
        "Repository": "https://github.com/ariebovenberg/gentools"
    },
    "split_keywords": [
        "generators",
        "itertools",
        "coroutines"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1412e495615dc5e47c2ad40768c661fdd70e9863cd6aec9d6aac07c2888d6fd8",
                "md5": "724e251cbd474d198052a894530070fc",
                "sha256": "75b7b0452691115ad11914e17c8c2b5f9b146b01f20167785e8b6d99b565d190"
            },
            "downloads": -1,
            "filename": "gentools-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "724e251cbd474d198052a894530070fc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 9045,
            "upload_time": "2024-01-29T06:43:30",
            "upload_time_iso_8601": "2024-01-29T06:43:30.344632Z",
            "url": "https://files.pythonhosted.org/packages/14/12/e495615dc5e47c2ad40768c661fdd70e9863cd6aec9d6aac07c2888d6fd8/gentools-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "214d68ba01cf9e6da4d024c13684d97206346e9ba11ad470516104e1cd13d857",
                "md5": "ab028c8c22a6b8ee11409af248241ab7",
                "sha256": "c692af51d5a8f7f3406ed8c39d6da686f4f2fe4dbfaa13ddb24035b0471d9305"
            },
            "downloads": -1,
            "filename": "gentools-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ab028c8c22a6b8ee11409af248241ab7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0.0",
            "size": 6702,
            "upload_time": "2024-01-29T06:43:32",
            "upload_time_iso_8601": "2024-01-29T06:43:32.161652Z",
            "url": "https://files.pythonhosted.org/packages/21/4d/68ba01cf9e6da4d024c13684d97206346e9ba11ad470516104e1cd13d857/gentools-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-29 06:43:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ariebovenberg",
    "github_project": "gentools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "gentools"
}
        
Elapsed time: 2.78727s