Created
June 29, 2025 02:04
-
-
Save rokon12/6576354d5b8a65a01e63fed9d67536f7 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