pytoolz/toolz — pull request #202 by eriknw (2014-07-07 04:28:59+00:00)
Title: Add keyword argument `numargs` to `curry`

This is useful to enforce variadic arguments to be non-empty, and to allow `TypeError` to be properly raised when currying extension and built-in types.

I want this feature for myself, and I will use `numargs` in `cytoolz.curried` for better error propagation.

"toolz/curried_exceptions.py" was removed, because the same functionality is obtained with `curry(merge_with, numargs=2)`.

`curry` was (finally) changed into a function and `Curry` a class. It was awkward to handle the keyword argument `numargs` with `curry` as a class only. See the ugly attempt made in 5a1aa9d. The class `Curry` is not in the main `toolz` namespace, and its signature is `Curry(func, args, kwargs, numargs=None)`. This is explicit. Explicit is good.

I would appreciate any feedback on the addition I made to the docstring that explains the `numargs` keyword.

`numargs` is specified as non-`None` for everything that is curried in `toolz.curried`. This is not strictly necessary, as the `try-except` approach works well for most functions in `toolz`. The main reason I specify `numargs` is so I can more easily make `cytoolz.curried` match. We may want to revert to `try-except` for slightly increased performance when possible.

As noted in the original discussion in the mailing list (https://groups.google.com/forum/#!topic/pytoolz/lAGRnwLah4g), `curry(f)(numargs=2)` can be used to apply `numargs` keyword argument to the curried function.