Skip to content

Instantly share code, notes, and snippets.

@billdozr
Last active December 15, 2015 11:59
Show Gist options
  • Save billdozr/5257287 to your computer and use it in GitHub Desktop.
Save billdozr/5257287 to your computer and use it in GitHub Desktop.
Java 8 :: Snippet 1 :: Compute product of even numbers (streams, lambda expressions, type inference, filters, reducers and optional type)
// Compute product of even numbers
OptionalInt r = Streams.intRange(1, 11) // [1..10]
.filter(n -> n % 2 == 0)
.reduce((acc, n) -> acc * n);
out.println(r.isPresent() ? r.getAsInt() : 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment