This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
huia/packages/core/ordering.huia

43 lines
971 B
Text
Raw Normal View History

2018-08-31 19:18:59 +12:00
deftrait Ordering as: ->
2018-09-08 21:08:53 +12:00
# This trait defines ordering comparisons for types.
def <Ordering::Result> compare_with other: Any
def equals? other: Any, as: ->
Huia::Primitive.match(self.compare_with(other), {
Ordering::Equal: true,
Any: false
})
end
def greater_than? other: Any, as: ->
Huia::Primitive.match(self.compare_with(other), {
Ordering::Greater: true,
Any: false
})
end
def greater_than_or_equal_to? other: Any, as: ->
Huia::Primitive.match(self.compare_with(other), {
Ordering::Greater: true,
Ordering::Equal: true,
Any: false
})
end
def less_than? other: Any, as: ->
Huia::Primitive.match(self.compare_with(other), {
Ordering::Less: true,
Any: false
})
end
def less_than_or_equal_to? other: Any, as: ->
Huia::Primitive.match(self.compare_with(other), {
Ordering::Less: true,
Ordering::Equal: true,
Any: false
})
end
end