#KT-1675 Fixed, renaming join() -> makeString() and adding an appendString() which reduces the possible number of appendables being created
This commit is contained in:
@@ -61,19 +61,3 @@ public inline fun <T> Array<T>.take(n: Int): List<T> {
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt takeWhile
|
||||
*/
|
||||
public inline fun <T> Array<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt join
|
||||
*/
|
||||
public inline fun <T> Array<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
|
||||
val buffer = StringBuilder(prefix)
|
||||
var first = true
|
||||
for (element in this) {
|
||||
if (first) first = false else buffer.append(separator)
|
||||
buffer.append(element)
|
||||
}
|
||||
buffer.append(postfix)
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
@@ -61,19 +61,3 @@ public inline fun <T> Iterable<T>.take(n: Int): List<T> {
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt takeWhile
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhileTo(ArrayList<T>(), predicate)
|
||||
|
||||
/**
|
||||
* Creates a string from all the elements separated using the *separator* and using the given *prefix* and *postfix* if supplied
|
||||
*
|
||||
* @includeFunctionBody ../../test/CollectionTest.kt join
|
||||
*/
|
||||
public inline fun <T> Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
|
||||
val buffer = StringBuilder(prefix)
|
||||
var first = true
|
||||
for (element in this) {
|
||||
if (first) first = false else buffer.append(separator)
|
||||
buffer.append(element)
|
||||
}
|
||||
buffer.append(postfix)
|
||||
return buffer.toString().sure()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user