4 ms·
I've never seen this name-in-operator syntax before. Does this work with all 2-character operators? Where is this documented and what are the usecases?
by CornCobs 5y ago
I've never seen this name-in-operator syntax before. Does this work with all 2-character operators? Where is this documented and what are the usecases?
- dragonwriter 5y agoIt's a hack using a single character binary operator and the way it's implemented for the type that serves as the main “operator” on between the paired use. > Where is this documented Insofar as it is, on the page linked. The underlying operator overloading mechanism that his leverages is documented in the official Python docs.
- CornCobs 5y agoOHHH. Looking at the Infix class carefully I realize it's not actually |add| as a single operator but using the right or __ror__ to partially apply the function, then using the left or __or__ to fully apply it. Wrapping it up in a decorator class is really neat!