Metadata-Version: 2.1
Name: betwixt
Version: 1.0.0
Summary: Infix operators for Python
Home-page: https://github.com/riccardomurri/betwixt
Author: Riccardo Murri
Author-email: riccardo.murri@gmail.com
License: GNU Lesser General Public License v3 or later (LGPLv3+)
Project-URL: Documentation, https://betwixt.readthedocs.io/
Project-URL: Changelog, https://betwixt.readthedocs.io/en/latest/changelog.html
Project-URL: Issue Tracker, https://github.com/riccardomurri/betwixt/issues
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Classifier: Operating System :: Unix
Classifier: Operating System :: POSIX
Classifier: Operating System :: Microsoft :: Windows
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 :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Utilities
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*

========
Overview
========



Easily make named infix binary operators in Python.

Demo time::

  # the only useful function in the module
  >>> from betwixt import infix_operator

  # any function of 2 arguments would do
  >>> from fnmatch import fnmatch

  # make the binary function into an operator, delimited by `*`
  >>> matches = infix_operator('*', fnmatch)

  # use it
  >>> 'foo.txt' *matches* '*.txt'
  True

  # other delimiters can be used
  >>> matches = infix_operator('|', fnmatch)
  >>> 'foo.txt' |matches| '*.txt'
  True

A decorator form can also be used::

  >>> @infix_operator('|')
  ... def contains(left, right):
  ...   return right in left

  >>> [1, 2, 3] |contains| 1
  True

  >>> [1, 2, 3] |contains| 0
  False

Finally, ``betwixt`` is provided as a shorter (and, perhaps, more
expressive) alias to ``infix_operator``::

  >>> from betwixt import betwixt

  >>> @betwixt('*')
  ... def joining(left, right):
  ...   return left.join(right)

  >>> '_' *joining* ['a', 'b', 'c']
  'a_b_c'

  >>> split_at = betwixt('//', lambda lhs, rhs: lhs.split(rhs))

  >>> 'a_b_c' //split_at// '_'
  ['a', 'b', 'c']

All these example operators and a few more are available in module
``betwixt.examples``.

The idea was taken from
http://code.activestate.com/recipes/384122-infix-operators/ and by a
similar C++ hack whose code on the web I cannot find any more, but no
actual code has been stolen.


Installation
============

::

    pip install betwixt

Documentation
=============


https://betwixt.readthedocs.io/


Development
===========

To run the all tests run::

    tox

Note, to combine the coverage data from all the tox environments run:

.. list-table::
    :widths: 10 90
    :stub-columns: 1

    - - Windows
      - ::

            set PYTEST_ADDOPTS=--cov-append
            tox

    - - Other
      - ::

            PYTEST_ADDOPTS=--cov-append tox


Copyright and license
=====================

Copyright (c) 2016-2020 Riccardo Murri <riccardo.murri@gmail.com>

This is free software, available under the terms and conditions
of the GNU LGPL -- see file LICENSE for details.


Changelog
=========

1.0.0 (2019-01-31)
------------------

* First release on PyPI.


