Metadata-Version: 2.4
Name: whatever
Version: 0.7
Summary: Easy way to make anonymous functions by partial application of operators.
Home-page: http://github.com/Suor/whatever
Author: Alexander Schepanovski
Author-email: suor.web@gmail.com
License: BSD
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: summary

The Whatever Object
===================

An easy way to make lambdas by partial application of python operators.

Inspired by Perl 6 one, see http://perlcabal.org/syn/S02.html#The_Whatever_Object


Usage
-----

.. code:: python

    from whatever import _, that

    # get a list of guys names
    names = map(_.name, guys)
    names = map(that.name, guys)

    odd = map(_ * 2 + 1, range(10))

    squares = map(_ ** 2, range(100))
    small_squares = filter(_ < 100, squares)

    best = max(tries, key=_.score)
    sort(guys, key=-that.height)

    factorial = lambda n: reduce(_ * _, range(2, n+1))

NOTE: chained comparisons cannot be implemented since there is no boolean overloading in python.


CAVEATS
-------

In some special cases whatever can cause confusion:

.. code:: python

    _.attr # this makes callable
    obj._  # this fetches '_' attribute of obj

    _[key] # this works too
    d[_]   # KeyError, most probably

    _._    # short for attrgetter('_')
    _[_]   # short for lambda d, k: d[k]

    if _ == 'Any value':
        # You will get here, definitely
        # `_ == something` produces callable, which is true

    [1, 2, _ * 2, None].index('hi') # => 2, since bool(_ * 2 == 'hi') is True


Also, whatever sometimes fails on late binding:

.. code:: python

    (_ * 2)('2') # -> NotImplemented
