tidied up the compareBy helper function a little; only compare based on the functions given

This commit is contained in:
James Strachan
2012-03-26 15:06:56 +01:00
parent bc17c7b4f3
commit 2803dfca08
2 changed files with 7 additions and 8 deletions
+6 -7
View File
@@ -1,14 +1,13 @@
package kotlin
import java.lang.Iterable
import java.util.Comparator
import java.util.Comparator
/**
* Helper method for implementing [[Comparable<T>]] methods using a list of functions
* to calculate the values to compare
*/
inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T,Any?>): Int {
* Helper method for implementing [[Comparable<T>]] methods using a list of functions
* to calculate the values to compare
*/
inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T, Any?>): Int {
require(functions.size > 0)
if (a === b) return 0
if (a == null) return - 1
if (b == null) return 1
@@ -18,7 +17,7 @@ inline fun <T> compareBy(a: T?, b: T?, vararg functions: Function1<T,Any?>): Int
val diff = compareValues(v1, v2)
if (diff != null) return diff
}
return compareValues(a, b)
return 0
}
/**