{"id":22712857,"url":"https://github.com/dgilland/fnc","last_synced_at":"2025-04-04T16:14:20.981Z","repository":{"id":57431671,"uuid":"144851548","full_name":"dgilland/fnc","owner":"dgilland","description":"Functional programming in Python with generators and other utilities.","archived":false,"fork":false,"pushed_at":"2023-10-03T15:50:28.000Z","size":128,"stargazers_count":265,"open_issues_count":0,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T15:08:12.763Z","etag":null,"topics":["functional","generators","utilities"],"latest_commit_sha":null,"homepage":"https://fnc.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/dgilland.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.rst","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst"}},"created_at":"2018-08-15T12:41:38.000Z","updated_at":"2025-03-27T07:52:18.000Z","dependencies_parsed_at":"2023-12-19T11:02:54.531Z","dependency_job_id":"954230e0-97a7-49e6-b085-c3df9a7b6c8e","html_url":"https://github.com/dgilland/fnc","commit_stats":{"total_commits":87,"total_committers":1,"mean_commits":87.0,"dds":0.0,"last_synced_commit":"b474d32d47feab0aa56e25f53c0cf24487aaa977"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilland%2Ffnc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilland%2Ffnc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilland%2Ffnc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgilland%2Ffnc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgilland","download_url":"https://codeload.github.com/dgilland/fnc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208145,"owners_count":20901570,"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":["functional","generators","utilities"],"created_at":"2024-12-10T13:39:21.327Z","updated_at":"2025-04-04T16:14:20.965Z","avatar_url":"https://github.com/dgilland.png","language":"Python","readme":"fnc\n***\n\n|version| |build| |coveralls| |license|\n\n\nFunctional programming in Python with generators and other utilities.\n\n\nLinks\n=====\n\n- Project: https://github.com/dgilland/fnc\n- Documentation: https://fnc.readthedocs.io\n- PyPI: https://pypi.python.org/pypi/fnc/\n- Github Actions: https://github.com/dgilland/fnc/actions\n\n\nFeatures\n========\n\n- Functional-style methods that work with and return generators.\n- Shorthand-style iteratees (callbacks) to easily filter and map data.\n- String object-path support for references nested data structures.\n- 100% test coverage.\n- Python 3.6+\n\n\nQuickstart\n==========\n\nInstall using pip:\n\n\n::\n\n    pip3 install fnc\n\n\nImport the main module:\n\n.. code-block:: python\n\n    import fnc\n\n\nStart working with data:\n\n.. code-block:: python\n\n    users = [\n        {'id': 1, 'name': 'Jack', 'email': 'jack@example.org', 'active': True},\n        {'id': 2, 'name': 'Max', 'email': 'max@example.com', 'active': True},\n        {'id': 3, 'name': 'Allison', 'email': 'allison@example.org', 'active': False},\n        {'id': 4, 'name': 'David', 'email': 'david@example.net', 'active': False}\n    ]\n\n\nFilter active users:\n\n.. code-block:: python\n\n    # Uses \"matches\" shorthand iteratee: dictionary\n    active_users = fnc.filter({'active': True}, users)\n    # \u003cfilter object at 0x7fa85940ec88\u003e\n\n    active_uesrs = list(active_users)\n    # [{'name': 'Jack', 'email': 'jack@example.org', 'active': True},\n    #  {'name': 'Max', 'email': 'max@example.com', 'active': True}]\n\n\nGet a list of email addresses:\n\n.. code-block:: python\n\n    # Uses \"pathgetter\" shorthand iteratee: string\n    emails = fnc.map('email', users)\n    # \u003cmap object at 0x7fa8577d52e8\u003e\n\n    emails = list(emails)\n    # ['jack@example.org', 'max@example.com', 'allison@example.org', 'david@example.net']\n\n\nCreate a ``dict`` of users keyed by ``'id'``:\n\n.. code-block:: python\n\n    # Uses \"pathgetter\" shorthand iteratee: string\n    users_by_id = fnc.keyby('id', users)\n    # {1: {'id': 1, 'name': 'Jack', 'email': 'jack@example.org', 'active': True},\n    #  2: {'id': 2, 'name': 'Max', 'email': 'max@example.com', 'active': True},\n    #  3: {'id': 3, 'name': 'Allison', 'email': 'allison@example.org', 'active': False},\n    #  4: {'id': 4, 'name': 'David', 'email': 'david@example.net', 'active': False}}\n\n\nSelect only ``'id'`` and ``'email'`` fields and return as dictionaries:\n\n.. code-block:: python\n\n    # Uses \"pickgetter\" shorthand iteratee: set\n    user_emails = list(fnc.map({'id', 'email'}, users))\n    # [{'email': 'jack@example.org', 'id': 1},\n    #  {'email': 'max@example.com', 'id': 2},\n    #  {'email': 'allison@example.org', 'id': 3},\n    #  {'email': 'david@example.net', 'id': 4}]\n\n\nSelect only ``'id'`` and ``'email'`` fields and return as tuples:\n\n.. code-block:: python\n\n    # Uses \"atgetter\" shorthand iteratee: tuple\n    user_emails = list(fnc.map(('id', 'email'), users))\n    # [(1, 'jack@example.org'),\n    #  (2, 'max@example.com'),\n    #  (3, 'allison@example.org'),\n    #  (4, 'david@example.net')]\n\n\nAccess nested data structures using object-path notation:\n\n.. code-block:: python\n\n    fnc.get('a.b.c[1][0].d', {'a': {'b': {'c': [None, [{'d': 100}]]}}})\n    # 100\n\n    # Same result but using a path list instead of a string.\n    fnc.get(['a', 'b', 'c', 1, 0, 'd'], {'a': {'b': {'c': [None, [{'d': 100}]]}}})\n    # 100\n\n\nCompose multiple functions into a generator pipeline:\n\n.. code-block:: python\n\n    from functools import partial\n\n    filter_active = partial(fnc.filter, {'active': True})\n    get_emails = partial(fnc.map, 'email')\n    get_email_domains = partial(fnc.map, lambda email: email.split('@')[1])\n\n    get_active_email_domains = fnc.compose(\n        filter_active,\n        get_emails,\n        get_email_domains,\n        set,\n    )\n\n    email_domains = get_active_email_domains(users)\n    # {'example.com', 'example.org'}\n\n\nOr do the same thing except using a terser \"partial\" shorthand:\n\n.. code-block:: python\n\n    get_active_email_domains = fnc.compose(\n        (fnc.filter, {'active': True}),\n        (fnc.map, 'email'),\n        (fnc.map, lambda email: email.split('@')[1]),\n        set,\n    )\n\n    email_domains = get_active_email_domains(users)\n    # {'example.com', 'example.org'}\n\n\nFor more details and examples, please see the full documentation at https://fnc.readthedocs.io.\n\n\n.. |version| image:: https://img.shields.io/pypi/v/fnc.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/fnc/\n\n.. |build| image:: https://img.shields.io/github/actions/workflow/status/dgilland/fnc/main.yml?branch=master\u0026style=flat-square\n    :target: https://github.com/dgilland/fnc/actions\n\n.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/fnc/master.svg?style=flat-square\n    :target: https://coveralls.io/r/dgilland/fnc\n\n.. |license| image:: https://img.shields.io/pypi/l/fnc.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/fnc/\n","funding_links":[],"categories":["Awesome Functional Python","Python"],"sub_categories":["Libraries"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgilland%2Ffnc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgilland%2Ffnc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgilland%2Ffnc/lists"}