Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0
-
None
Description
The .each{} gdk method should return its own collection, unaltered. That will make it possible to chain .each{} methods, as demonstrated in the code below. It may be desirable to look at other gdk methods as well.
THE CODE AS IT IS NOW (in Groovy 1.0):
def numbers = ['one', 'two', 'three', 4, 5];
def maxSize = 0;
numbers
.collect
.each
{
println "${it.toString().padRight(maxSize)} : ${it.getClass().name}";
};
OUTPUT:
one : java.lang.String
two : java.lang.String
three : java.lang.String
4 : java.lang.Integer
5 : java.lang.Integer
THE CODE WHERE each{} RETURNS ITS COLLECTION:
def numbers = ['one', 'two', 'three', 4, 5];
def maxSize = 0;
numbers
.each
.each
{
println "${it.toString().padRight(maxSize)} : ${it.getClass().name}";
};