3 ms·
This is a pretty cool recipe. The precedence is determined by the overridden operator. In this case the "|" operator has low precedence.¹ For a high preceden
by raymondh 5y ago
This is a pretty cool recipe.
The precedence is determined by the overridden operator. In this case the "|" operator has low precedence.¹ For a high precedence operator, override "%" with __mod__ and __rmod__:
4 |add| 5 %mul% 6 |add| 7 # mul happens before add
¹ https://docs.python.org/3/reference/expressions.html#operator-precedence https://docs.python.org/3/reference/expressions.html#operato...
- CornCobs 5y agoNice! It just so happens that %% is used to denote infix operators in R (which can have arbitrary names). Like the %in% operator in base, or the famous pipe operator %>% from magrittr
- kragen 5y agoOoh, I had no idea. That might swing the balance in favor of %beside%, since R is super popular.