From c485eda1c2964a6204781a70d839012998df1086 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sun, 22 Nov 2015 09:24:45 +0300 Subject: [PATCH] Make zip operation symmetrical for CharSequences (missed to generalize parameter before). --- libraries/stdlib/src/generated/_Strings.kt | 9 +++++++-- .../kotlin-stdlib-gen/src/templates/Generators.kt | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 1f941b8a837..50824913775 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -931,14 +931,14 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair> { +public infix fun CharSequence.zip(other: CharSequence): List> { return zip(other) { c1, c2 -> c1 to c2 } } /** * Returns a list of values built from characters of both char sequences with same indexes using provided [transform]. List has length of shortest char sequence. */ -public inline fun CharSequence.zip(other: String, transform: (Char, Char) -> V): List { +public inline fun CharSequence.zip(other: CharSequence, transform: (Char, Char) -> V): List { val length = Math.min(this.length, other.length) val list = ArrayList(length) for (i in 0..length-1) { @@ -947,6 +947,11 @@ public inline fun CharSequence.zip(other: String, transform: (Char, Char) -> return list } +@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) +public infix fun CharSequence.zip(other: String): List> { + return zip(other) { c1, c2 -> c1 to c2 } +} + /** * Returns a sequence from the given collection. */ diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 2987527f58a..85f3ce5236b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -555,7 +555,7 @@ fun generators(): List { } } - templates add f("zip(other: String, transform: (Char, Char) -> V)") { + templates add f("zip(other: CharSequence, transform: (Char, Char) -> V)") { only(CharSequences) doc { """ @@ -597,6 +597,18 @@ fun generators(): List { } templates add f("zip(other: String)") { + infix(true) + only(CharSequences) + deprecate { forBinaryCompatibility } + returns("List>") + body { + """ + return zip(other) { c1, c2 -> c1 to c2 } + """ + } + } + + templates add f("zip(other: CharSequence)") { infix(true) only(CharSequences) doc {