This commit is contained in:
Andrey Breslav
2010-11-08 14:36:37 +03:00
parent 0845cb27a0
commit 369b197478
35 changed files with 958 additions and 0 deletions
+19
View File
@@ -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
}
+3
View File
@@ -0,0 +1,3 @@
interface class IComparable<in T> {
fun compareTo(other : T) : Int
}