Shared publicly  - 
We had to scramble to get FluentIterable released this quarter, but it's public reception has been great!
Guava 12.0 introduces FluentIterable, a new and improved way of doing many of the things you can already do with the Iterables class. Instead of static methods for transforming, filtering and querying, FluentIterable wraps another Iterable (or is extended directly) and provides instance methods for doing those same things. The methods that create views return FluentIterable themselves, allowing you to chain calls. The result is much more readable code when you have a series of operations you want to apply in a row. Just look at the difference in the following equivalent examples.


Iterable<Dessert> desserts = ...
ImmutableSet<Filling> pieFillings = ImmutableSet.copyOf(
. . Iterables.transform(
. . . . .Iterables.limit(Iterables.filter(desserts, Pie.class), 10)


ImmutableSet<Filling> pieFillings = FluentIterable.from(desserts)
. . .filter(Pie.class)
. . .limit(10)
. . .transform(Pie.GET_FILLING_FUNCTION)
. . .toImmutableSet();

With FluentIterable, the code reads from top to bottom rather than inside out and it’s much easier to see what the arguments to each method are. While you should still take care not to overuse Guava’s functional APIs where they aren’t needed (see, FluentIterable goes a long way to make the places you use it more readable.

-- +Colin Decker, Guava contributor and future team member
from(Iterable<E> iterable) Returns a fluent iterable that wraps iterable , or iterable itself if it is already a FluentIterable . E · get(int position) Returns the element at the specified posit...
Add a comment...