baml.ops.Compare

A *total* ordering: every pair of values is ordered, and the ordering is antisymmetric and transitive. There is no partial counterpart.

Reference version

Signature

interface baml.ops.Compare

A 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 45066720

Required instance methods

function

cmp

(self, other: Self) -> baml.ops.Ordering throws never

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

function

clamp

(self, min: Self, max: Self) -> Self throws never

Clamps 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.

function

ge

(self, other: Self) -> bool throws never

Whether self orders after other or equals it. Defaults to self.cmp(other) != Ordering.Less.

function

gt

(self, other: Self) -> bool throws never

Whether self orders strictly after other. Defaults to self.cmp(other) == Ordering.Greater.

function

le

(self, other: Self) -> bool throws never

Whether self orders before other or equals it. Defaults to self.cmp(other) != Ordering.Greater.

function

lt

(self, other: Self) -> bool throws never

Whether self orders strictly before other. Defaults to self.cmp(other) == Ordering.Less.

function

max

(self, other: Self) -> Self throws never

Ties return self, so max is stable when two values compare Equal without being interchangeable.

function

min

(self, other: Self) -> Self throws never

Ties return self, matching max.