pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.66k stars 259 forks source link

flip bug with > 2 parameters #509

Closed efagerberg closed 3 years ago

efagerberg commented 3 years ago
from toolz.functoolz import flip

def foo(x, y):
    return x - y

flip(foo, 5, 2)
# -3, works fine

def foo(x, y, z):
    return x - y + z

flip(foo, 5, 4, 3)
# expected 2
    301     def __call__(self, *args, **kwargs):
    302         try:
--> 303             return self._partial(*args, **kwargs)
    304         except TypeError as exc:
    305             if self._should_curry(args, kwargs, exc):

TypeError: flip() takes 3 positional arguments but 4 were given

flip(foo, 5, 4)
# expect a function that takes x as a parameter
    301     def __call__(self, *args, **kwargs):
    302         try:
--> 303             return self._partial(*args, **kwargs)
    304         except TypeError as exc:
    305             if self._should_curry(args, kwargs, exc):

    728     [1, 2, 3]
    729     """
--> 730     return func(b, a)
    731 
    732 

TypeError: foo() missing 1 required positional argument: 'z'
efagerberg commented 3 years ago

Never-mind, I realize this is intended, the flip function does not take arbitrary amounts of args. And doing so might make the example of supplying the first and third params harder.