Fix implementation of Iterable<T>.take

#KT-4780 Fixed
This commit is contained in:
Alexander Udalov
2014-03-28 15:45:28 +04:00
parent 829cd95469
commit e3fffe275b
3 changed files with 21 additions and 8 deletions
+5 -3
View File
@@ -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
}