From 5a474adf5956d38316bb709930affc338c3ff678 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 26 Aug 2015 16:40:55 +0300 Subject: [PATCH] Unify selector parameter names. --- libraries/stdlib/src/generated/_Ordering.kt | 132 +++++++++--------- libraries/stdlib/src/kotlin/util/Ordering.kt | 22 +-- .../src/templates/Ordering.kt | 16 +-- 3 files changed, 85 insertions(+), 85 deletions(-) diff --git a/libraries/stdlib/src/generated/_Ordering.kt b/libraries/stdlib/src/generated/_Ordering.kt index 50e3e14dba0..71445697032 100644 --- a/libraries/stdlib/src/generated/_Ordering.kt +++ b/libraries/stdlib/src/generated/_Ordering.kt @@ -296,157 +296,157 @@ public fun > Sequence.sorted(): Sequence { } /** - * 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 > Array.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > Array.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List { + 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 > BooleanArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > BooleanArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Boolean) -> R?): List { + 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 > ByteArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > ByteArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Byte) -> R?): List { + 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 > CharArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > CharArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Char) -> R?): List { + 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 > DoubleArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > DoubleArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Double) -> R?): List { + 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 > FloatArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > FloatArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Float) -> R?): List { + 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 > IntArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > IntArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Int) -> R?): List { + 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 > LongArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > LongArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Long) -> R?): List { + 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 > ShortArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > ShortArray.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Short) -> R?): List { + 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 > Iterable.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareBy(order)) +public inline fun > Iterable.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List { + 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 > Sequence.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { - return sortedWith(compareBy(order)) +public inline fun > Sequence.sortedBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): Sequence { + 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 > Array.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > Array.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List { + 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 > BooleanArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Boolean) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > BooleanArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Boolean) -> R?): List { + 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 > ByteArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Byte) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > ByteArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Byte) -> R?): List { + 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 > CharArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Char) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > CharArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Char) -> R?): List { + 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 > DoubleArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Double) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > DoubleArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Double) -> R?): List { + 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 > FloatArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Float) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > FloatArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Float) -> R?): List { + 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 > IntArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Int) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > IntArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Int) -> R?): List { + 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 > LongArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Long) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > LongArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Long) -> R?): List { + 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 > ShortArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (Short) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > ShortArray.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (Short) -> R?): List { + 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 > Iterable.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): List { - return sortedWith(compareByDescending(order)) +public inline fun > Iterable.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): List { + 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 > Sequence.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R?): Sequence { - return sortedWith(compareByDescending(order)) +public inline fun > Sequence.sortedByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> R?): Sequence { + return sortedWith(compareByDescending(selector)) } /** diff --git a/libraries/stdlib/src/kotlin/util/Ordering.kt b/libraries/stdlib/src/kotlin/util/Ordering.kt index 3c3c25e0307..b7d0ab3c2ff 100644 --- a/libraries/stdlib/src/kotlin/util/Ordering.kt +++ b/libraries/stdlib/src/kotlin/util/Ordering.kt @@ -41,7 +41,7 @@ public fun 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 > 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 compareBy(vararg functions: (T) -> Comparable<*>?): Comparator { +public fun compareBy(vararg selectors: (T) -> Comparable<*>?): Comparator { return object : Comparator { - 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 comparator(vararg functions: (T) -> Comparable<*>?): Comparator compareBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator { +inline public fun compareBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { - 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 compareBy(comparator: Comparator, inlineOptions(Inli /** * Creates a descending comparator using the function to transform value to a [Comparable] instance for comparison. */ -inline public fun compareByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator { +inline public fun compareByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { - 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 compareByDescending(comparator: Comparator, 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 Comparator.thenBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator { +inline public fun Comparator.thenBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { 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 Comparator.thenBy(comparator: Comparator, inlineO * Creates a descending comparator using the primary comparator and * the function to transform value to a [Comparable] instance for comparison. */ -inline public fun Comparator.thenByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) comparable: (T) -> Comparable<*>?): Comparator { +inline public fun Comparator.thenByDescending(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) selector: (T) -> Comparable<*>?): Comparator { return object : Comparator { 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) } } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt index ee9e937500d..35cefb9b6ef 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt @@ -140,7 +140,7 @@ fun ordering(): List { } } - 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") @@ -148,21 +148,21 @@ fun ordering(): List { 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") @@ -170,17 +170,17 @@ fun ordering(): List { 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))" } }