baml.ops.Compare
A *total* ordering: every pair of values is ordered, and the ordering is antisymmetric and transitive. There is no partial counterpart.
Signature
interface baml.ops.CompareA total ordering: every pair of values is ordered, and the ordering is antisymmetric and transitive. There is no partial counterpart.
Backs the <, <=, > and >= operators, and is what a T extends Compare bound asks for. Closest to Rust's
Ord: requires Equals
is the counterpart of Ord: Eq, and — unlike PartialOrd — the order is
total for every implementor, float included.
Must be consistent with baml.ops.Equals: self.cmp(other) is
Ordering.Equal exactly when self.eq(other).
cmp is the only required method — lt/le/gt/ge/min/max/clamp
all derive from it, and an implementor overrides them only to be faster. An
override is responsible for agreeing with cmp.
An implementation may panic, which throws never does not rule out; a
caller working through a generic bound cannot enumerate the panics and must
be ready for one it cannot describe. See baml.ops.Add.
Source:<builtin>/baml/ns_ops/comparison.bamlbytes 4506–6720
Required instance methods
Three-way comparison of self against other.
The one method with no default; the rest of the interface is defined in terms of it.
Default instance methods
clamp
(self, min: Self, max: Self) -> Self throws neverClamps self into the range [min, max].
Callers should pass min <= max; if min > max the result is always
min, because the lower clamp runs after the upper one. Written as the
min/max chain rather than a three-way match so it agrees with
int.clamp / float.clamp on that degenerate input too.
ge
(self, other: Self) -> bool throws neverWhether self orders after other or equals it. Defaults to
self.cmp(other) != Ordering.Less.
gt
(self, other: Self) -> bool throws neverWhether self orders strictly after other. Defaults to
self.cmp(other) == Ordering.Greater.
le
(self, other: Self) -> bool throws neverWhether self orders before other or equals it. Defaults to
self.cmp(other) != Ordering.Greater.
lt
(self, other: Self) -> bool throws neverWhether self orders strictly before other. Defaults to
self.cmp(other) == Ordering.Less.
max
(self, other: Self) -> Self throws neverTies return self, so max is stable when two values compare Equal
without being interchangeable.
min
(self, other: Self) -> Self throws neverTies return self, matching max.