Created
October 9, 2020 05:21
-
-
Save gchiam/78227f4f7d2dd20a7e2f32bb3dc98b88 to your computer and use it in GitHub Desktop.
Generate permutations of Boolean values
This file contains 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
Stream.of(true, false) | |
.map(b2 -> Stream.of(true, false) | |
.map(b3 -> List.of(b2, b3)) | |
.collect(Collectors.toList())) | |
.flatMap(Collection::stream) | |
.collect(Collectors.toList()); | |
// [[true, true], [true, false], [false, true], [false, false]] | |
Stream.of(true, false) | |
.map(b1 -> Stream.of(true, false) | |
.map(b2 -> Stream.of(true, false) | |
.map(b3 -> List.of(b1, b2, b3) | |
.collect(Collectors.toList())) | |
.flatMap(Collection::stream) | |
.collect(Collectors.toList())) | |
.flatMap(Collection::stream) | |
.collect(Collectors.toList()); | |
// [[true, true, true], [true, true, false], [true, false, true], [true, false, false], [false, true, true], [false, true, false], [false, false, true], [false, false, false]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment