Created
June 29, 2025 02:04
-
-
Save rokon12/06405432e866d8e6f282eb45e7b872dc to your computer and use it in GitHub Desktop.
Code snippet from The Coding Café - snippet-2.java
This file contains hidden or 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
List<Integer> runningMax = values.stream() | |
.gather(Gatherers.scan( | |
() -> Integer.MIN_VALUE, // 1️⃣ Start with smallest possible value | |
Integer::max // 2️⃣ Keep the maximum at each step | |
)) | |
.toList(); | |
System.out.println("Running maximum: " + runningMax); | |
// Output: [-2147483648, 1, 5, 5, 8, 8, 9, 9, 9, 9] | |
// ↑ initial ↑ 5>1 ↑ 8>5 ↑ 9>8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment