Skip to content

Commit 6b670e3

Browse files
committed
Add gatherer for scan
1 parent 82b4246 commit 6b670e3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Inbuilt Gatherers?
22

33
1. Scan
4-
2.
4+
2. FixedWindow
55
3.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.streams.practice.gatherers;
2+
3+
import java.util.List;
4+
import java.util.stream.Gatherers;
5+
import java.util.stream.Stream;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.condition.EnabledOnJre;
9+
import org.junit.jupiter.api.condition.JRE;
10+
11+
12+
class ScanTest {
13+
@Test
14+
@EnabledOnJre(JRE.JAVA_25)
15+
void scanTest() {
16+
final List<String> actual =
17+
Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9)
18+
.gather(Gatherers.scan(() -> "", (string, number) -> string + number))
19+
.toList();
20+
21+
final List<String> expected =
22+
List.of("1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789");
23+
Assertions.assertEquals(expected, actual);
24+
}
25+
}

0 commit comments

Comments
 (0)