-
-
Save ppajdek/0ab8cfffb2987f1488416cc0f00271cb to your computer and use it in GitHub Desktop.
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
int imperative() { | |
int sum = 0; | |
int limit = 10; | |
for (int i = 0; i < 100; i++) { | |
if (i % 3 == 0 && i % 2 == 0) { | |
if (limit-- == 0) break; | |
sum += i * i; | |
} | |
} | |
return sum; | |
} | |
int declarative() { | |
return IntStream.range(0, 100) | |
.filter(i -> i % 3 == 0) | |
.filter(i -> i % 2 == 0) | |
.limit(10) | |
.map(i -> i * i) | |
.sum(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment