Skip to content

Instantly share code, notes, and snippets.

@rokon12
Created June 29, 2025 02:29
Show Gist options
  • Save rokon12/9b8034b27968b973882b5830da49af28 to your computer and use it in GitHub Desktop.
Save rokon12/9b8034b27968b973882b5830da49af28 to your computer and use it in GitHub Desktop.
Code snippet from The Coding Café - snippet-2.java
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