{"id":16734895,"url":"https://github.com/vopaaz/functional-piped","last_synced_at":"2026-02-04T13:17:11.283Z","repository":{"id":193176734,"uuid":"688275880","full_name":"Vopaaz/functional-piped","owner":"Vopaaz","description":"Write s(iterator).map(func) instead of map(func, iterator)","archived":false,"fork":false,"pushed_at":"2024-04-16T05:02:18.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T18:11:15.336Z","etag":null,"topics":["python","python3"],"latest_commit_sha":null,"homepage":"","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/Vopaaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-09-07T02:39:53.000Z","updated_at":"2023-12-20T06:17:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"73bc19c5-6794-46e3-a8af-70d9338836e4","html_url":"https://github.com/Vopaaz/functional-piped","commit_stats":null,"previous_names":["vopaaz/functional-piped"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Vopaaz/functional-piped","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vopaaz%2Ffunctional-piped","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vopaaz%2Ffunctional-piped/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vopaaz%2Ffunctional-piped/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vopaaz%2Ffunctional-piped/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vopaaz","download_url":"https://codeload.github.com/Vopaaz/functional-piped/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vopaaz%2Ffunctional-piped/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29085074,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["python","python3"],"created_at":"2024-10-13T00:04:13.240Z","updated_at":"2026-02-04T13:17:11.269Z","avatar_url":"https://github.com/Vopaaz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# functional-piped\n\n![Codecov](https://img.shields.io/codecov/c/github/Vopaaz/functional-piped?style=for-the-badge\u0026token=gOatZaMQ9U)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/functional-piped?style=for-the-badge\u0026)\n![PyPI](https://img.shields.io/pypi/v/functional-piped?style=for-the-badge\u0026)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/Vopaaz/functional-piped/CI-master.yml?branch=master\u0026style=for-the-badge)\n\nPython has native support for some functional programming functions such as `map` and `filter`.\nThis library allows you to use them in a \"piped\" way,\ni.e. `s(iterable).map(func)` instead of `map(func, iterable)`,\nbecause in any slightly more complex scenarios, the former is much more readable.\n\nFor example,\n\n```python\n(s(iterable)\n    .map(func0)\n    .filter(func1)\n    .to(list))\n```\n\nmakes much more sense than\n\n```python\nlist(\n    filter(\n        func1,\n        map(func0, iterable)\n    )\n)\n```\n\n## Installation\n\n`pip install functional-piped`\n\n## Usage\n\n```python\n\u003e\u003e\u003e from funcpipe import Stream as s\n```\n\nThen you can use `.map`, `.filter`, `.reduce`, `.foreach`, and `.zip`\nto manipulate your iterable in a functional programming way.\nIf the result is still an iterable, you can use `.to()` to collect it into any data type\n\n```python\n\u003e\u003e\u003e s([1, 2, 3]).map(lambda x: x + 1).to(list)\n[2, 3, 4]\n\n\u003e\u003e\u003e s([1, 2, 3]).map(lambda x: x + 1).filter(lambda x: x % 2).to(list)\n[2]\n\n\u003e\u003e\u003e s([1, 2, 3]).map(lambda x: x + 1).to(set)\n{2, 3, 4}\n\n\u003e\u003e\u003e (s([1, 2, 3])\n...     .map(lambda x: x + 1)            # [2, 3, 4]\n...     .filter(lambda x: x % 2 == 0)    # [2, 4]\n...     .reduce(lambda x, y: x + y))     # 2 + 4 = 6\n6\n\n\u003e\u003e\u003e s([1, 2, 3]).foreach(print)\n1\n2\n3\n```\n\n\n### Using `.zip` and `.star`\n\nOne common use case in Python is\n\n```python\na_list = [...]\nb_list = [...]\n\nfor a, b in zip(a_list, b_list):\n    ...\n```\n\nTo write equivalent code, you can use `s(a_list).zip(b_list)` to zip the two lists together,\nand use the `.star` attribute to apply `.foreach` to the unpacked zipped values\n\n```python\n\u003e\u003e\u003e s([1, 2]).zip([3, 4]).to(list)\n[(1, 3), (2, 4)]\n\n\u003e\u003e\u003e s([1, 2]).zip([3, 4]).star.foreach(lambda x, y: print(f\"{x} + {y}\"))\n1 + 3\n2 + 4\n```\n\nThe same thing applies to map and filter:\n\n```python\n\u003e\u003e\u003e s([1, 2]).zip([3, 4]).star.map(lambda x, y: x + y).to(list)\n[4, 6]\n```\n\nIf you don't use `.star`, the callback of each function will receive a tuple:\n\n```python\n\u003e\u003e\u003e s([1, 2]).zip([3, 4]).map(lambda x: x[0] + x[1]).to(list)\n[4, 6]\n```\n\nNaming of `.star` comes from the `itertools.starmap`, but this concept also\napplies to `.filter` and `.foreach`, so instead of creating a `.starmap` method for `Stream`, we use the above mentioned syntax there.\n\n\n## Iterable Reusability\n\n`s(obj)` behaves exactly the same as `obj` in terms of \"reusability\" when calling iterator/iterable\nrelated methods.\n\nIf `obj` is an iterable, not iterator:\n\n```python\n\u003e\u003e\u003e obj = [1, 2, 3]\n\u003e\u003e\u003e stream = s(obj)\n\n\u003e\u003e\u003e stream.map(lambda x: x + 1).to(list)\n[2, 3, 4]\n\n\u003e\u003e\u003e stream.map(lambda x: x + 1).to(list)\n[2, 3, 4]\n```\n\nIf `obj` is an iterator:\n\n```python\n\u003e\u003e\u003e obj = iter(range(1, 4))\n\u003e\u003e\u003e stream = s(obj)\n\n\u003e\u003e\u003e stream.map(lambda x: x + 1).to(list)\n[2, 3, 4]\n\n\u003e\u003e\u003e stream.map(lambda x: x + 1).to(list)\n[]\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvopaaz%2Ffunctional-piped","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvopaaz%2Ffunctional-piped","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvopaaz%2Ffunctional-piped/lists"}