ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

.each{} returns null instead of the object on which it is being called #398

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
It's inconsistent with standard Groovy and what it results in is that you can't 
build up some neat groovy chains which make up the essence of the language:
{{{[[1, 2, 3], [2, 3], [0, 2]].
  each {it.remove(1)}.
  collect {it + [56]}.
  findAll {it.size() >= 3}}}}
In standard Groovy the above code results in `[[1, 3, 56]]`

Here's a practical example from my code, which I had to leave dynamic for now 
because of this issue:
<code language="groovy">@Lazy List<Rectangle> windowRegions = {
  WindowBoundariesUtils.openBoundaries(WINDOW_CONTROLS_MARKER, image).
    each {WindowBoundariesUtils.updateBoundaries(TYPE1_BOUNDARY_MARKERS, it, image)}.
    collect {it.toRectangle()}.
    findAll {it != null}
}(){/code>

Original issue reported on code.google.com by justn...@mail.ru on 16 Sep 2011 at 10:54

GoogleCodeExporter commented 8 years ago
Man.. I wanted to add a markup to the post and look what it's done to it. And I 
don't have rights to edit it

Original comment by justn...@mail.ru on 16 Sep 2011 at 10:56

GoogleCodeExporter commented 8 years ago
I got the same result in groovy++ (http://groovypp.appspot.com/)

List l= [[1, 2, 3], [2, 3], [0, 2]]
.each {it.remove(1)}        // [[1, 3], [2], [0]] 
.collect {it + [56]}        // [[1, 3, 56], [2, 56], [0, 56]]
.findAll {it.size() >= 3}   // [[1, 3, 56]]

Original comment by gabriel....@googlemail.com on 22 Sep 2011 at 8:00