Initial
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
type Comparison<in T> = {T, T => Int}
|
||||
|
||||
fun naturalOrder<in T : IComparable<T>>(a : T, b : T) : Int = a.compareTo(b)
|
||||
|
||||
fun castingNaturalOrder(a : Object, b : Object) : Int = a.as<Comparable<Object>>.compareTo(b.as<Comparable<Object>>)
|
||||
|
||||
enum class ComparisonResult {
|
||||
LS,EQ, GR
|
||||
}
|
||||
|
||||
type MatchableComparison<in T> = {T, T, => ComparisonResult}
|
||||
|
||||
fun asMatchableComparison<T>(cmp : Comparison<T>) : MatchableComparison<T> = {a, b =>
|
||||
val res = cmp(a, b)
|
||||
if (res == 0) return ComparisonResult.EQ
|
||||
if (res < 0) return ComparisonResult.LS
|
||||
return ComparisonResult.GR
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
interface class IComparable<in T> {
|
||||
fun compareTo(other : T) : Int
|
||||
}
|
||||
Reference in New Issue
Block a user