Fix implementation of Iterable<T>.take
#KT-4780 Fixed
This commit is contained in:
@@ -1001,9 +1001,11 @@ public fun <T> Collection<T>.take(n: Int) : List<T> {
|
||||
public fun <T> Iterable<T>.take(n: Int) : List<T> {
|
||||
var count = 0
|
||||
val list = ArrayList<T>(n)
|
||||
for (item in this)
|
||||
if (count++ >= n)
|
||||
list.add(item)
|
||||
for (item in this) {
|
||||
if (count++ == n)
|
||||
break
|
||||
list.add(item)
|
||||
}
|
||||
return list
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user