Metadata-Version: 2.0
Name: one
Version: 0.1.0
Summary: Not all nor any. Just the one.
Home-page: https://github.com/mgaitan/one
Author: Martín Gaitán
Author-email: gaitan@gmail.com
License: BSD
Keywords: one
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.5
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4

====================================
``one``, the missing Python function
====================================

.. image:: https://pypip.in/d/one/badge.png
        :target: https://pypi.python.org/pypi/one


Not ``all`` nor ``any``: just the ``one``.

``one`` is a simple function to check if there is a unique value
that evaluates to True in an iterable, and return it.

Examples:

.. code-block:: python

    >>> from one import one
    >>> one((True, False, False))
    True
    >>> one((True, False, True))
    False
    >>> one((0, 0, 'a'))
    'a'
    >>> one((0, False, None))
    False
    >>> one((True, True))
    False
    >>> one(('', 1))
    1

Install
--------

::

    pip install one



Use cases
----------

A very frequent case is when you have values that must exclude each others.


.. code-block:: python

    class ShopStore(models.Model):
        address = models.CharField(max_length=200, null=True, blank=True)
        is_online = models.BooleanField(default=False)

        def clean(self):
            if not one((self.address, self.is_online)):
                raise models.ValidationError(u'A shop must be online or physical, but not both')




.. attention:: send me your examples!



