To be clear, this post is not about using Groovy to make collect calls (Are collect phone calls still a thing? Do people nowadays even know what they are?). No, I am talking about calling methods named collect
, which may seem banal but actually warrants attention, especially in light of Groovy 3's long-awaited and much-anticipated release.
Groovy has long provided Closures and extension methods on Iterable
and Iterator
to implement Java 8 Stream-like capabilities, even when running on Java 7 or earlier.
Using these capabilities to, say, square all even numbers between 1 and 10, would look akin to this:
def evenSquares = (1..10)