{"id":16482646,"url":"https://github.com/ariebovenberg/gentools","last_synced_at":"2025-03-23T12:32:19.234Z","repository":{"id":57433657,"uuid":"117867722","full_name":"ariebovenberg/gentools","owner":"ariebovenberg","description":"Tools for generators, generator functions, and generator-based coroutines","archived":false,"fork":false,"pushed_at":"2024-03-25T05:42:17.000Z","size":244,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-25T06:44:29.320Z","etag":null,"topics":["coroutines","decorators","functional","python-generators","python3"],"latest_commit_sha":null,"homepage":"http://gentools.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ariebovenberg.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-01-17T17:14:37.000Z","updated_at":"2024-04-15T06:51:02.025Z","dependencies_parsed_at":"2023-02-12T04:33:28.847Z","dependency_job_id":"35464fe5-287b-4463-8c49-da4e2b428385","html_url":"https://github.com/ariebovenberg/gentools","commit_stats":{"total_commits":118,"total_committers":3,"mean_commits":"39.333333333333336","dds":"0.15254237288135597","last_synced_commit":"c4ab678a9452cbd997ea5b85981a66fe0c6931bc"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariebovenberg%2Fgentools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariebovenberg%2Fgentools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariebovenberg%2Fgentools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ariebovenberg%2Fgentools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ariebovenberg","download_url":"https://codeload.github.com/ariebovenberg/gentools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221850482,"owners_count":16891634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutines","decorators","functional","python-generators","python3"],"created_at":"2024-10-11T13:11:32.472Z","updated_at":"2024-10-28T15:46:39.280Z","avatar_url":"https://github.com/ariebovenberg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"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\u0026style=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 \u003c1.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   \u003e\u003e\u003e @reusable\n   ... def countdown(value, step):\n   ...     while value \u003e 0:\n   ...         yield value\n   ...         value -= step\n\n   \u003e\u003e\u003e from_3 = countdown(3, step=1)\n   \u003e\u003e\u003e list(from_3)\n   [3, 2, 1]\n   \u003e\u003e\u003e list(from_3)\n   [3, 2, 1]\n   \u003e\u003e\u003e isinstance(from_3, countdown)  # generator func is wrapped in a class\n   True\n   \u003e\u003e\u003e from_3.step  # attribute access to arguments\n   1\n   \u003e\u003e\u003e 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   \u003e\u003e\u003e @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 \u003c 100:\n   ...         newvalue = yield value\n   ...         if newvalue \u003e value:\n   ...             value = newvalue\n   ...     return value\n\n   \u003e\u003e\u003e gen = my_max(5)\n   \u003e\u003e\u003e next(gen)\n   'the current max is: 5'\n   \u003e\u003e\u003e gen.send(11.3)\n   'the current max is: 11'\n   \u003e\u003e\u003e 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   \u003e\u003e\u003e def try_until_positive(outvalue):\n   ...     value = yield outvalue\n   ...     while value \u003c 0:\n   ...         value = yield 'not positive, try again'\n   ...     return value\n\n   \u003e\u003e\u003e @relay(try_until_positive)\n   ... def my_max(value):\n   ...     while value \u003c 100:\n   ...         newvalue = yield value\n   ...         if newvalue \u003e value:\n   ...             value = newvalue\n   ...     return value\n\n   \u003e\u003e\u003e gen = my_max(5)\n   \u003e\u003e\u003e next(gen)\n   5\n   \u003e\u003e\u003e gen.send(-4)\n   'not positive, try again'\n   \u003e\u003e\u003e gen.send(-1)\n   'not positive, try again'\n   \u003e\u003e\u003e gen.send(8)\n   8\n   \u003e\u003e\u003e gen.send(104)\n   StopIteration(104)\n\n- make python 2/3 compatible generators with ``return``. \n  (`gentools` version \u003c1.2 only)\n\n.. code-block:: python\n\n   \u003e\u003e\u003e @py2_compatible\n   ... def my_max(value):\n   ...     while value \u003c 100:\n   ...         newvalue = yield value\n   ...         if newvalue \u003e value:\n   ...             value = newvalue\n   ...     return_(value)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariebovenberg%2Fgentools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fariebovenberg%2Fgentools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fariebovenberg%2Fgentools/lists"}