removed Iterator.toString() as it changes the iterator state, the default is fine and folks should be explicit about iterating over an iterator. Also disabled the default limit on the iterator on join(); if folks want to limit the join they should be explicit
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaCollections.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
//
|
||||||
|
// This file contains methods which are optimised for working on Collection / Array collections where the size
|
||||||
|
// could be used to implement a more optimal solution
|
||||||
|
//
|
||||||
|
// See [[GenerateStandardLib.kt]] for more details
|
||||||
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaIterables.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaIterablesLazy.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaIterablesLazy.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
@@ -67,7 +67,7 @@ inline fun <T> Array<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeWhil
|
|||||||
*
|
*
|
||||||
* @includeFunction ../../test/CollectionTest.kt join
|
* @includeFunction ../../test/CollectionTest.kt join
|
||||||
*/
|
*/
|
||||||
inline fun <T> Array<T>.join(separator: String, prefix: String = "", postfix: String = "") : String {
|
inline fun <T> Array<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
|
||||||
val buffer = StringBuilder(prefix)
|
val buffer = StringBuilder(prefix)
|
||||||
var first = true
|
var first = true
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaCollections.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
//
|
||||||
|
// This file contains methods which are optimised for working on Collection / Array collections where the size
|
||||||
|
// could be used to implement a more optimal solution
|
||||||
|
//
|
||||||
|
// See [[GenerateStandardLib.kt]] for more details
|
||||||
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaIterables.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaCollections.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaCollections.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
//
|
||||||
|
// This file contains methods which are optimised for working on Collection / Array collections where the size
|
||||||
|
// could be used to implement a more optimal solution
|
||||||
|
//
|
||||||
|
// See [[GenerateStandardLib.kt]] for more details
|
||||||
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaIterables.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaIterables.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// NOTE this file is auto-generated from stdlib/src/kotlin/JavaIterablesLazy.kt
|
// NOTE this file is auto-generated from src/kotlin/JavaIterablesLazy.kt
|
||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
import kotlin.util.*
|
import kotlin.util.*
|
||||||
@@ -67,7 +67,7 @@ inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T> = takeW
|
|||||||
*
|
*
|
||||||
* @includeFunction ../../test/CollectionTest.kt join
|
* @includeFunction ../../test/CollectionTest.kt join
|
||||||
*/
|
*/
|
||||||
inline fun <T> Iterable<T>.join(separator: String, prefix: String = "", postfix: String = "") : String {
|
inline fun <T> Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
|
||||||
val buffer = StringBuilder(prefix)
|
val buffer = StringBuilder(prefix)
|
||||||
var first = true
|
var first = true
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
|
|||||||
@@ -129,20 +129,13 @@ private class TakeWhileIterator<T>(val iterator: java.util.Iterator<T>, val pred
|
|||||||
*
|
*
|
||||||
* @includeFunction ../../test/iterators/IteratorsTest.kt joinConcatenatesTheFirstNElementsAboveAThreshold
|
* @includeFunction ../../test/iterators/IteratorsTest.kt joinConcatenatesTheFirstNElementsAboveAThreshold
|
||||||
*/
|
*/
|
||||||
inline fun <T> java.util.Iterator<T>.join(separator: String, prefix: String = "", postfix: String = "", limit: Int = 20) : String {
|
inline fun <T> java.util.Iterator<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "", limit: Int? = null) : String {
|
||||||
val buffer = StringBuilder(prefix)
|
val buffer = StringBuilder(prefix)
|
||||||
var first = true; var count = 0
|
var first = true; var count = 0
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
if (first) first = false else buffer.append(separator)
|
if (first) first = false else buffer.append(separator)
|
||||||
if (++count <= limit) buffer.append(element) else break
|
if (limit == null || ++count <= limit) buffer.append(element) else break
|
||||||
}
|
}
|
||||||
if (count > limit) buffer.append("...")
|
if (limit != null && count > limit) buffer.append("...")
|
||||||
return buffer.append(postfix).toString().sure()
|
return buffer.append(postfix).toString().sure()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a comma-separated representation of no more than the first 10 elements
|
|
||||||
*
|
|
||||||
* @includeFunction ../../test/iterators/IteratorsTest.kt toStringJoinsNoMoreThanTheFirstTenElements
|
|
||||||
*/
|
|
||||||
inline fun <T> java.util.Iterator<T>.toString(): String = join(separator = ", ", limit = 10)
|
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ package kotlin
|
|||||||
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
//
|
||||||
|
// This file contains methods which are optimised for working on Collection / Array collections where the size
|
||||||
|
// could be used to implement a more optimal solution
|
||||||
|
//
|
||||||
|
// See [[GenerateStandardLib.kt]] for more details
|
||||||
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new List containing the results of applying the given function to each element in this collection
|
* Returns a new List containing the results of applying the given function to each element in this collection
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ inline fun <T> java.lang.Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<
|
|||||||
*
|
*
|
||||||
* @includeFunction ../../test/CollectionTest.kt join
|
* @includeFunction ../../test/CollectionTest.kt join
|
||||||
*/
|
*/
|
||||||
inline fun <T> java.lang.Iterable<T>.join(separator: String, prefix: String = "", postfix: String = "") : String {
|
inline fun <T> java.lang.Iterable<T>.join(separator: String = ", ", prefix: String = "", postfix: String = "") : String {
|
||||||
val buffer = StringBuilder(prefix)
|
val buffer = StringBuilder(prefix)
|
||||||
var first = true
|
var first = true
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class IteratorsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Test fun toStringJoinsNoMoreThanTheFirstTenElements() {
|
Test fun toStringJoinsNoMoreThanTheFirstTenElements() {
|
||||||
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().toString())
|
assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().join(limit = 10))
|
||||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.toString())
|
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.join(limit = 10))
|
||||||
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toString())
|
assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.join())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user