kachayev/fn.py — pull request #16 by pyos (2013-01-23 15:17:49+00:00)
Title: Scala-style partial operator binding fails on 3+ underscores.

The current implementation of `underscore.py` fails with some scary-looking error messages if more than one underscore per operator is used. For example:

```python
> (_ + _ * _)(1, 2)
TypeError: unsupported operand type(s) for +: 'int' and 'function'

in line 1, ``: None
in ./fn/underscore.py line 64, `__call__`: return curry(self._callback, *args)
in ./fn/op.py line 27, `curry`: return curry(f(arg), *rest) if rest else f(arg)
in ./fn/op.py line 27, `curry`: return curry(f(arg), *rest) if rest else f(arg)
in ./fn/underscore.py line 18, ``: call = lambda arg1: lambda arg2: f(self(arg1), other(arg2))
```

Unfortunately, the current underscore implementation was too cryptic for me to understand :) That's why the attached commits rewrite it completely. But hey, at least it works now! :)

```python
> (_ + _ * _)(1, 2)

> (_ + _ * _)(1, 2, 3)
7
```

(As a side note, I took the liberty of changing the string representations so that the `eval(repr(x)) == x` rule holds.)