babel-operator-overload-plugin
Overload operators in local scope.
This is a babel plugin allowing you to "overload" operators without affecting the whole program's scope.
For example, let's say you wanted the pipe (|
) operator do just that, pipe. So basically what we want is that left | right
becomes right(left)
.
This can be done using the defineBinaryOperator
macro provided by the plugin:
;
Easy, no? Now we can use this operator in a program:
; const map = list;const filter = list;const mul = a * b;const gt = b > a; const numbers = 1 2 3 4 5 6 7 8 | | console; // [ 12, 15, 18, 21, 24 ]
Et voilà!
The overloads are completely bound to the scope they're declared in, so for example this works:
{ return leftX + rightX leftY + rightY ;} { return 1 2 + 3 5;} 1 + 2 // 3 // [ 4, 7 ]