import java.util.stream.*; class X { Object test(Stream s, Boolean b1, Boolean b2) { return s .flatMap(p1 -> IntStream.of(1, 2, 3) .flatMap(p2 -> IntStream.of(4, 5) .flatMap(p3 -> IntStream.of(6, 7) .flatMap(p4 -> Stream.of(b1, b2) .flatMap(p5 -> Stream.of(b1, b2) .map(p6 -> null)))))); } }