def reverse_apply(self): """Creates a Function that reversely apply positional arguments. Reversed positional arguments application: >>> minus = Function(lambda a, b: a - b) >>> minus(8, 5) 3 >>> subtract = minus.reverse_apply() >>> subtract(8, 5) -3 ``flip`` is a read-only property for easier referencing: >>> minus.flip(8, 5) -3 >>> minus.flip.flip(8, 5) 3 Flip operator ``~`` >>> (~minus)(8, 5) -3 >>> subtract = ~minus >>> subtract(8, 5) -3 """ return self.clone(flip(self.invoke))
def test_flip(): f = lambda a, b: a - b ns = [(2, 1), (1, 2), (0, 1), (1, 0)] for a, b in ns: assert f(a, b) != flip(f)(a, b) assert flip(f)(a, b) == flip(f)(a, b) assert flip(f)(a, b) != flip(flip(f))(a, b) assert flip(flip(f))(a, b) == f(a, b)