SimpleStream, a simpler way to use Java 8 Streams

When Java 8 came out last year, it finally introduced lambdas, a much-awaited language feature, and along with it, a new way to manipulate data in the form of streams. While streams make it significantly easier to perform aggregate operations on collections, common tasks still involve boilerplate code that could easily be eliminated. For example:

// Collect names into a list
people.stream().map(Person::getName).collect(Collectors.toList());

// Compute sum of salaries
employees.stream().collect(Collectors.summingInt(Employee::getSalary)));

Wouldn’t it be nicer to write something like this instead?

// Collect names into a list
stream(people).map(Person::getName).toList();

// Compute sum of salaries
stream(employees).map(Employee::getSalary).sumAsInt();

SimpleStream is a wrapper around Java 8 Streams that lets you write more concise code, like in the above example. It’s a single Java file that you can drop into your project and start using immediately.

Learn more and download on GitHub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s