Groovy Goodness: Transform Elements While Flattening [Snippet

published 14.01.2020 15:42

We can use themethod in Groovy to flatten a collection that contains other collections into a single collection with all elements.

We can pass a closure as an extra argument to themethod to transform each element that is flattened.

The argument of the closure is the element from the original collection.

In the following example, we first use the method without a closure argument.

Then we pass a closure argument and transform the element:

by {{Node.Authors[0].Realname }} from dzone.com

Free awesomeness straight to your inbox!

Sign up now for this free newsletter to receive hand picked content, covering topics like Lifestyle, Business & Technology.

Free Newsletter Sign up now!

..or jump directly to the latest posts!