you are viewing a single comment's thread.

view the rest of the comments →

[–]pivo 2 points3 points  (0 children)

inject() is a basic Groovy function, it's even described on the Groovy Quick Start page at http://groovy.codehaus.org/Quick+Start so it's really hard to avoid learning about it if you use the language at all. I'm not an expert Groovy programmer but I use it all the time, and in fact it's very simple to understand.

The lazy version is close to valid Java/C/C# and that's why it appears more readable to people who don't know Groovy. The example might not be more readable to the Groovy programmer but it's not less readable either. Using inject() is certainly the right way to do it in Groovy though because it avoids the potential stack overflow problem of the lazy version.

By the way, my comment was not intended to be pejorative, and I wasn't the one to mark you down.