Property definitions

core $ Comparable :: defaultinit
# The ancestor of class where objects are in a total order.
# In order to work, the method '<' has to be redefined.
interface Comparable
	# What `self` can be compared to?
	type OTHER: Comparable

	# Is `self` lesser than `other`?
	fun <(other: OTHER): Bool is abstract

	# not `other` < `self`
	# Note, the implementation must ensure that: `(x<=y) == (x<y or x==y)`
	fun <=(other: OTHER): Bool do return not other < self

	# not `self` < `other`
	# Note, the implementation must ensure that: `(x>=y) == (x>y or x==y)`
	fun >=(other: OTHER): Bool do return not self < other

	# `other` < `self`
	fun >(other: OTHER): Bool do return other < self

	# -1 if <, +1 if > and 0 otherwise
	# Note, the implementation must ensure that: (x<=>y == 0) == (x==y)
	fun <=>(other: OTHER): Int
	do
		if self < other then
			return -1
		else if other < self then
			return 1
		else
			return 0
		end
	end

	# c <= self <= d
	fun is_between(c: OTHER, d: OTHER): Bool
	do
		return c <= self and self <= d
	end

	# The maximum between `self` and `other` (prefers `self` if equals).
	fun max(other: OTHER): OTHER
	do
		if self < other then
			return other
		else
			return self
		end
	end

	# The minimum between `self` and `c` (prefer `self` if equals)
	fun min(c: OTHER): OTHER
	do
		if c < self then
			return c
		else
			return self
		end
	end
end
lib/core/kernel.nit:313,1--371,3