Skip to content

Instantly share code, notes, and snippets.

@rokon12
Created June 29, 2025 02:24
Show Gist options
  • Save rokon12/eef55a38d98ecf00c099cae3c76ad94e to your computer and use it in GitHub Desktop.
Save rokon12/eef55a38d98ecf00c099cae3c76ad94e to your computer and use it in GitHub Desktop.
List<Integer> runningMax = values.stream()
.gather(Gatherers.scan(
() -> Integer.MIN_VALUE,
Integer::max
))
.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