From 941167e2411263f27a16d0e157a74c359065f15d Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sun, 29 Nov 2015 04:30:31 +0300 Subject: [PATCH] Revert "Drop deprecated toGenerator and toLinkedList." until RC --- libraries/stdlib/src/generated/_Arrays.kt | 72 +++++++++++++++++++ .../stdlib/src/generated/_Collections.kt | 8 +++ libraries/stdlib/src/generated/_Sequences.kt | 8 +++ libraries/stdlib/src/generated/_Strings.kt | 8 +++ libraries/stdlib/src/kotlin/util/Functions.kt | 18 +++++ .../src/templates/Snapshots.kt | 7 ++ 6 files changed, 121 insertions(+) create mode 100644 libraries/stdlib/src/kotlin/util/Functions.kt diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index eb692f652c8..f6d9a2f8652 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -5788,6 +5788,78 @@ public fun ShortArray.toHashSet(): HashSet { return toCollection(HashSet(mapCapacity(size))) } +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun Array.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun BooleanArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun ByteArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun CharArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun DoubleArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun FloatArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun IntArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun LongArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun ShortArray.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + /** * Returns a [List] containing all elements. */ diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 271e4417b26..bfb0f881881 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -1049,6 +1049,14 @@ public fun Iterable.toHashSet(): HashSet { return toCollection(HashSet(mapCapacity(collectionSizeOrDefault(12)))) } +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun Iterable.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + /** * Returns a [List] containing all elements. */ diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 53d73e6db77..41d7466a0f0 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -507,6 +507,14 @@ public fun Sequence.toHashSet(): HashSet { return toCollection(HashSet()) } +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun Sequence.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + /** * Returns a [List] containing all elements. */ diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 5228f1b0f06..d2cd1fd840e 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -782,6 +782,14 @@ public fun String.toHashSet(): HashSet { return toCollection(HashSet(mapCapacity(length))) } +/** + * Returns a [LinkedList] containing all elements. + */ +@Deprecated("Use toCollection(LinkedList()) instead.", ReplaceWith("toCollection(LinkedList())")) +public fun String.toLinkedList(): LinkedList { + return toCollection(LinkedList()) +} + /** * Returns a [List] containing all characters. */ diff --git a/libraries/stdlib/src/kotlin/util/Functions.kt b/libraries/stdlib/src/kotlin/util/Functions.kt new file mode 100644 index 00000000000..04c05822fda --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/Functions.kt @@ -0,0 +1,18 @@ +package kotlin + +/** + * Converts a function that takes one argument and returns a value of the same type to a generator function. + * The generator function calls this function, passing to it either [initialValue] on the first iteration + * or the previously returned value on subsequent iterations, and returns the returned value. + */ +@Deprecated("This function will be removed soon. If you need generator function to create a sequence, use the 'sequence' function instead.") +public fun Function1.toGenerator(initialValue: T): Function0 { + var nextValue: T? = initialValue + return { + nextValue?.let { result -> + nextValue = this@toGenerator(result) + result + } + } +} + diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt index 05419ba206b..f2e26e2fc35 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt @@ -110,6 +110,13 @@ fun snapshots(): List { body { "return this.toArrayList()" } } + templates add f("toLinkedList()") { + include(Strings) + doc { "Returns a [LinkedList] containing all elements." } + returns("LinkedList") + deprecate { Deprecation("Use toCollection(LinkedList()) instead.", replaceWith = "toCollection(LinkedList())") } + } + templates add f("toMap(selector: (T) -> K)") { inline(true) deprecate(Strings) { forBinaryCompatibility }