Unify selector parameter names.

This commit is contained in:
Ilya Gorbunov
2015-08-26 16:40:55 +03:00
parent 7d33599fc2
commit 5a474adf59
3 changed files with 85 additions and 85 deletions
+66 -66
View File
@@ -296,157 +296,157 @@ public fun <T : Comparable<T>> Sequence<T>.sorted(): Sequence<T> {
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List<T> {
return sortedWith(compareBy(order))
public inline fun <T, R : Comparable<R>> Array<out T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List<T> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> BooleanArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List<Boolean> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> BooleanArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Boolean) -> R?): List<Boolean> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> ByteArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List<Byte> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> ByteArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Byte) -> R?): List<Byte> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> CharArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List<Char> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> CharArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Char) -> R?): List<Char> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> DoubleArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List<Double> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> DoubleArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Double) -> R?): List<Double> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> FloatArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List<Float> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> FloatArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Float) -> R?): List<Float> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> IntArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List<Int> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> IntArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Int) -> R?): List<Int> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> LongArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List<Long> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> LongArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Long) -> R?): List<Long> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> ShortArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List<Short> {
return sortedWith(compareBy(order))
public inline fun <R : Comparable<R>> ShortArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Short) -> R?): List<Short> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List<T> {
return sortedWith(compareBy(order))
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List<T> {
return sortedWith(compareBy(selector))
}
/**
* Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [order] function.
* Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Sequence<T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence<T> {
return sortedWith(compareBy(order))
public inline fun <T, R : Comparable<R>> Sequence<T>.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): Sequence<T> {
return sortedWith(compareBy(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Array<out T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List<T> {
return sortedWith(compareByDescending(order))
public inline fun <T, R : Comparable<R>> Array<out T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> BooleanArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List<Boolean> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> BooleanArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Boolean) -> R?): List<Boolean> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> ByteArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List<Byte> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> ByteArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Byte) -> R?): List<Byte> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> CharArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List<Char> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> CharArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Char) -> R?): List<Char> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> DoubleArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List<Double> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> DoubleArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Double) -> R?): List<Double> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> FloatArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List<Float> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> FloatArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Float) -> R?): List<Float> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> IntArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List<Int> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> IntArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Int) -> R?): List<Int> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> LongArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List<Long> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> LongArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Long) -> R?): List<Long> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <R : Comparable<R>> ShortArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List<Short> {
return sortedWith(compareByDescending(order))
public inline fun <R : Comparable<R>> ShortArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Short) -> R?): List<Short> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List<T> {
return sortedWith(compareByDescending(order))
public inline fun <T, R : Comparable<R>> Iterable<T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List<T> {
return sortedWith(compareByDescending(selector))
}
/**
* Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function.
* Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [selector] function.
*/
public inline fun <T, R : Comparable<R>> Sequence<T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence<T> {
return sortedWith(compareByDescending(order))
public inline fun <T, R : Comparable<R>> Sequence<T>.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): Sequence<T> {
return sortedWith(compareByDescending(selector))
}
/**
+11 -11
View File
@@ -41,7 +41,7 @@ public fun <T : Any> compareValuesBy(a: T?, b: T?, vararg functions: (T) -> Comp
}
/**
* Compares two values using the specified sequence of functions to calculate the result of the comparison.
* Compares two values using the specified functions [selectors] to calculate the result of the comparison.
* The functions are called sequentially, receive the given values [a] and [b] and return [Comparable]
* objects. As soon as the [Comparable] instances returned by a function for [a] and [b] values do not
* compare as equal, the result of that comparison is returned.
@@ -104,9 +104,9 @@ public fun <T : Comparable<*>> compareValues(a: T?, b: T?): Int {
* objects. As soon as the [Comparable] instances returned by a function for `a` and `b` values do not
* compare as equal, the result of that comparison is returned from the [Comparator].
*/
public fun <T> compareBy(vararg functions: (T) -> Comparable<*>?): Comparator<T> {
public fun <T> compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, *functions)
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, *selectors)
}
}
@@ -119,9 +119,9 @@ public fun <T> comparator(vararg functions: (T) -> Comparable<*>?): Comparator<T
/**
* Creates a comparator using the function to transform value to a [Comparable] instance for comparison.
*/
inline public fun <T> compareBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator<T> {
inline public fun <T> compareBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, comparable)
public override fun compare(a: T, b: T): Int = compareValuesBy(a, b, selector)
}
}
@@ -138,9 +138,9 @@ inline public fun <T, K> compareBy(comparator: Comparator<K>, inlineOptions(Inli
/**
* Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison.
*/
inline public fun <T> compareByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator<T> {
inline public fun <T> compareByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, comparable)
public override fun compare(a: T, b: T): Int = compareValuesBy(b, a, selector)
}
}
@@ -160,11 +160,11 @@ inline public fun <T, K> compareByDescending(comparator: Comparator<K>, inlineOp
* Creates a comparator comparing values after the primary comparator defined them equal. It uses
* the function to transform value to a [Comparable] instance for comparison.
*/
inline public fun <T> Comparator<T>.thenBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator<T> {
inline public fun <T> Comparator<T>.thenBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenBy.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(a, b, comparable)
return if (previousCompare != 0) previousCompare else compareValuesBy(a, b, selector)
}
}
}
@@ -186,11 +186,11 @@ inline public fun <T, K> Comparator<T>.thenBy(comparator: Comparator<K>, inlineO
* Creates a descending comparator using the primary comparator and
* the function to transform value to a [Comparable] instance for comparison.
*/
inline public fun <T> Comparator<T>.thenByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator<T> {
inline public fun <T> Comparator<T>.thenByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator<T> {
return object : Comparator<T> {
public override fun compare(a: T, b: T): Int {
val previousCompare = this@thenByDescending.compare(a, b)
return if (previousCompare != 0) previousCompare else compareValuesBy(b, a, comparable)
return if (previousCompare != 0) previousCompare else compareValuesBy(b, a, selector)
}
}
}
@@ -140,7 +140,7 @@ fun ordering(): List<GenericFunction> {
}
}
templates add f("sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") {
templates add f("sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?)") {
exclude(Strings)
inline(true)
returns("List<T>")
@@ -148,21 +148,21 @@ fun ordering(): List<GenericFunction> {
doc {
"""
Returns a list of all elements sorted according to natural sort order of the value returned by specified [order] function.
Returns a list of all elements sorted according to natural sort order of the value returned by specified [selector] function.
"""
}
returns("SELF", Sequences)
doc(Sequences) {
"Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [order] function."
"Returns a sequence that yields elements of this sequence sorted according to natural sort order of the value returned by specified [selector] function."
}
body {
"return sortedWith(compareBy(order))"
"return sortedWith(compareBy(selector))"
}
}
templates add f("sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?)") {
templates add f("sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?)") {
exclude(Strings)
inline(true)
returns("List<T>")
@@ -170,17 +170,17 @@ fun ordering(): List<GenericFunction> {
doc {
"""
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [order] function.
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified [selector] function.
"""
}
returns("SELF", Sequences)
doc(Sequences) {
"Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [order] function."
"Returns a sequence that yields elements of this sequence sorted descending according to natural sort order of the value returned by specified [selector] function."
}
body {
"return sortedWith(compareByDescending(order))"
"return sortedWith(compareByDescending(selector))"
}
}