Dart comparison operators
I don't think so... but you can use a simple mixin for implementing operators based on the Comparable
implementation:
mixin Compare<T> on Comparable<T> { bool operator <=(T other) => this.compareTo(other) <= 0; bool operator >=(T other) => this.compareTo(other) >= 0; bool operator <(T other) => this.compareTo(other) < 0; bool operator >(T other) => this.compareTo(other) > 0; bool operator ==(other) => other is T && this.compareTo(other) == 0;}
Example usage:
class Vec with Comparable<Vec>, Compare<Vec> { final double x; final double y; Vec(this.x, this.y); @override int compareTo(Vec other) => (x.abs() + y.abs()).compareTo(other.x.abs() + other.y.abs());}main() { print(Vec(1, 1) > Vec(0, 0)); print(Vec(1, 0) > Vec(0, 0)); print(Vec(0, 0) == Vec(0, 0)); print(Vec(1, 1) <= Vec(2, 0));}