refactored foreach() -> forEach() as per Cedric's excellent suggestion http://devnet.jetbrains.net/message/5454105#5454105
This commit is contained in:
@@ -20,7 +20,7 @@ trait Traversable<T> {
|
||||
fun filter(predicate: (T)-> Boolean) : Collection<T>
|
||||
|
||||
/** Performs the given operation on each element inside the collection */
|
||||
fun foreach(operation: (element: T)-> Unit)
|
||||
fun forEach(operation: (element: T)-> Unit)
|
||||
|
||||
/** Returns a new collection containing the results of applying the given function to each element in this collection */
|
||||
fun <T, R> java.lang.Iterable<T>.map(transform : (T)-> R) : Collection<R>
|
||||
|
||||
@@ -125,7 +125,7 @@ class CollectionTest() : TestCase() {
|
||||
|
||||
fun testForeach() {
|
||||
var count = 0
|
||||
data.foreach{ count += it.length }
|
||||
data.forEach{ count += it.length }
|
||||
assertEquals(6, count)
|
||||
}
|
||||
|
||||
|
||||
@@ -55,17 +55,17 @@ class IoTest() : TestCase() {
|
||||
val reader = sample()
|
||||
|
||||
/* TODO would be nicer maybe to write this as
|
||||
reader.lines.foreach { ... }
|
||||
reader.lines.forEach { ... }
|
||||
|
||||
as we could one day maybe one day write that as
|
||||
for (line in reader.lines)
|
||||
|
||||
if the for(elem in thing) {...} statement could act as syntax sugar for
|
||||
thing.foreach{ elem -> ... }
|
||||
thing.forEach{ elem -> ... }
|
||||
|
||||
if thing is not an Iterable/array/Iterator but has a suitable foreach method
|
||||
if thing is not an Iterable/array/Iterator but has a suitable forEach method
|
||||
*/
|
||||
reader.foreachLine{
|
||||
reader.forEachLine{
|
||||
list.add(it)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class Kt1149Test() : TestCase() {
|
||||
res.add("anonymous.foo()")
|
||||
}
|
||||
})
|
||||
list.foreach{ it.foo() }
|
||||
list.forEach{ it.foo() }
|
||||
Assert.assertEquals("anonymous.foo()", res[0])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user