Hacking Infix Operators into Python with Decorators
tomerfiliba.com
tomerfiliba.com
You can scroll up a little for some of the other definitions.
This is just toy code of course, but it's fun sometimes to be able to say something like
SELECT * FROM>> dfrm <<WHERE>> COL('A') < 0.5
for a DataFrame "dfrm" with a column "A"
I like the "<< _ >>" syntax better myself, even though the "|_|" syntax uses fewer characters.
Oh it is! Now never use this.
args = list(x,y)
do.call("+",args) from operator import add
add(x, y)
Like in your example, you can't simply give it more args (since infix operators are binary operators and may not be associative). But you could combine it with some other builtins like so: from operator import add
reduce(add, [x, y, z])
Of course, for the specific case of addition, you can simply use the builtin "sum()" function, which is almost equivalent to above (sum() assumes an initial value of 0 by default, so sum(list) === reduce(add, list, 0))