Last active
December 15, 2015 11:59
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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