Metadata-Version: 2.1
Name: fnc
Version: 0.1.0
Summary: Functional utilities
Home-page: https://github.com/dgilland/fnc
Author: Derrick Gilland
Author-email: dgilland@gmail.com
License: MIT License
Keywords: fnc
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Provides-Extra: dev
Provides-Extra: dev
Requires-Dist: coverage; extra == 'dev'
Requires-Dist: flake8; extra == 'dev'
Requires-Dist: pylint; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-cov; extra == 'dev'
Requires-Dist: Sphinx; extra == 'dev'
Requires-Dist: sphinx-rtd-theme; extra == 'dev'
Requires-Dist: tox; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Requires-Dist: wheel; extra == 'dev'

fnc
***

|version| |travis| |coveralls| |license|


Functional utilities


Links
=====

- Project: https://github.com/dgilland/fnc
- Documentation: https://fnc.readthedocs.io
- PyPI: https://pypi.python.org/pypi/fnc/
- TravisCI: https://travis-ci.org/dgilland/fnc


Features
========

- Functional-style methods that work with and return generators.
- Shorthand-style iteratees (callbacks) to easily filter and map data.
- String object-path support for references nested data structures.
- 100% test coverage.


Quickstart
==========

Install using pip:


::

    pip install fnc


Import the main module:

.. code-block:: python

    import fnc


Start working with data:

.. code-block:: python

    users = [{'id': 1, 'name': 'Jack', 'email': 'jack@example.org', 'active': True},
             {'id': 2, 'name': 'Max', 'email': 'max@example.com', 'active': True},
             {'id': 3, 'name': 'Allison', 'email': 'allison@example.org', 'active': False},
             {'id': 4, 'name': 'David', 'email': 'david@example.net', 'active': False}]


Filter active users:

.. code-block:: python

    # Uses "matches" shorthand iteratee: dictionary
    active_users = fnc.filter({'active': True}, users)
    # <filter object at 0x7fa85940ec88>

    active_uesrs = list(active_users)
    # [{'name': 'Jack', 'email': 'jack@example.org', 'active': True},
    #  {'name': 'Max', 'email': 'max@example.com', 'active': True}]


Get a list of email addresses:

.. code-block:: python

    # Uses "pathgetter" shorthand iteratee: string
    emails = fnc.map('email', users)
    # <map object at 0x7fa8577d52e8>

    emails = list(emails)
    # ['jack@example.org', 'max@example.com', 'allison@example.org', 'david@example.net']


Create a ``dict`` of users keyed by ``'id'``:

.. code-block:: python

    # Uses "pathgetter" shorthand iteratee: string
    users_by_id = fnc.keyby('id', users)
    # {1: {'id': 1, 'name': 'Jack', 'email': 'jack@example.org', 'active': True},
    #  2: {'id': 2, 'name': 'Max', 'email': 'max@example.com', 'active': True},
    #  3: {'id': 3, 'name': 'Allison', 'email': 'allison@example.org', 'active': False},
    #  4: {'id': 4, 'name': 'David', 'email': 'david@example.net', 'active': False}}


Select only ``'id'`` and ``'email'`` fields and return as dictionaries:

.. code-block:: python

    # Uses "pickgetter" shorthand iteratee: set
    user_emails = list(fnc.map({'id', 'email'}, users))
    # [{'email': 'jack@example.org', 'id': 1},
    #  {'email': 'max@example.com', 'id': 2},
    #  {'email': 'allison@example.org', 'id': 3},
    #  {'email': 'david@example.net', 'id': 4}]


Select only ``'id'`` and ``'email'`` fields and return as tuples:

.. code-block:: python

    # Uses "atgetter" shorthand iteratee: tuple
    user_emails = list(fnc.map(('id', 'email'), users))
    # [(1, 'jack@example.org'),
    #  (2, 'max@example.com'),
    #  (3, 'allison@example.org'),
    #  (4, 'david@example.net')]


Access nested data structures using object-path notation:

.. code-block:: python

    fnc.get('a.b.c[1][0].d', {'a': {'b': {'c': [None, [{'d': 100}]]}}})
    # 100

    # Same result but using a path list instead of a string.
    fnc.get(['a', 'b', 'c', 1, 0, 'd'], {'a': {'b': {'c': [None, [{'d': 100}]]}}})
    # 100


Compose multiple functions into a generator pipeline:

.. code-block:: python

    from functools import partial

    filter_active = partial(fnc.filter, {'active': True})
    get_emails = partial(fnc.map, 'email')
    get_email_domains = partial(fnc.map, lambda email: email.split('@')[1])

    pipe_active_email_domains = fnc.compose(filter_active,
                                            get_emails,
                                            get_email_domains)

    email_domains = set(pipe_active_email_domains(users))
    # {'example.com', 'example.org'}


For more details and examples, please see the full documentation at https://fnc.readthedocs.io.



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

.. |travis| image:: https://img.shields.io/travis/dgilland/fnc/master.svg?style=flat-square
    :target: https://travis-ci.org/dgilland/fnc

.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/fnc/master.svg?style=flat-square
    :target: https://coveralls.io/r/dgilland/fnc

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

Changelog
=========


v0.1.0 (2018-08-15)
-------------------

- First release.

License
=======

The MIT License (MIT)

Copyright (c) 2018, Derrick Gilland

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


