Last active
September 27, 2019 14:11
-
-
Save orend/208ec76e505f8c15f6ba78b45e25e449 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
// given | |
Stream<Integer> infiniteStream = Stream.iterate(0, i -> i + 2); | |
// when | |
List<Integer> collect = infiniteStream | |
.limit(10) | |
.collect(Collectors.toList()); | |
// then | |
assertEquals(collect, Arrays.asList(0, 2, 4, 6, 8, 10, 12, 14, 16, 18)); | |
--------------------------------- | |
int[] fibs = {0, 1}; | |
Stream<Integer> fibonacci = Stream.generate(() -> { | |
int result = fibs[1]; | |
int fib3 = fibs[0] + fibs[1]; | |
fibs[0] = fibs[1]; | |
fibs[1] = fib3; | |
return result; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment