Created
June 29, 2025 02:17
-
-
Save rokon12/1c8c7e059433d3d7955c0a178a8a4436 to your computer and use it in GitHub Desktop.
Code snippet from The Coding Café - snippet-3.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<Long> runningProduct = values.stream() | |
| .gather(Gatherers.scan( | |
| () -> 1L, // 1️⃣ Start with identity for multiplication | |
| (acc, val) -> acc * val // 2️⃣ Multiply accumulated value by current | |
| )) | |
| .toList(); | |
| System.out.println("Running product: " + runningProduct); | |
| // Output: [1, 1, 5, 15, 120, 240, 2160, 8640, 60480, 362880] | |
| // ↑ ↑ ↑ ↑ ↑ | |
| // init 1×1 1×5 5×3 15×8 (and so on...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment