Groovy improvements

So far we have been using Twitter4J as a vanilla API, with a smattering of Groovy, so we have not been bringing any of the Groovier features to bear. Now that we know a little bit about the API, let's try to improve our usage by using some Groovy features. In this section, we will progressively improve our usage of the Twitter4J APIs by selectively using the features that Groovy provides. One of the most obvious features to use is closures.

A Groovier way to find friends

In the previous examples, we iterated over our friends and printed out their details. What if we were to provide a method that takes a closure to apply to each friend or follower? In this example, we add these methods to a script, along with a follow method, ...

Get Groovy for Domain-specific Languages - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.