@Test void unfoldShouldGenerateAFiniteStream() { Stream<Integer> unfolded = StreamUtils.unfold(1, i -> { if (i < 10) { return Optional.of(i + 1); } else { return Optional.empty(); } }); assertThat(unfolded.collect(Guavate.toImmutableList())) .contains(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
public static <T> Stream<T> unfold(T seed, Function<T, Optional<T>> generator) { return StreamSupport.stream(new UnfoldSpliterator(seed, generator), !PARALLEL); }
StreamUtils { public static <T> Stream<T> unfold(T seed, Function<T, Optional<T>> generator) { return StreamSupport.stream(new UnfoldSpliterator(seed, generator), !PARALLEL); } }
StreamUtils { public static <T> Stream<T> unfold(T seed, Function<T, Optional<T>> generator) { return StreamSupport.stream(new UnfoldSpliterator(seed, generator), !PARALLEL); }  }
StreamUtils { public static <T> Stream<T> unfold(T seed, Function<T, Optional<T>> generator) { return StreamSupport.stream(new UnfoldSpliterator(seed, generator), !PARALLEL); }  @SafeVarargs static Stream<T> ofNullables(T... array); static Stream<T> ofNullable(T[] array); static Stream<T> ofOptional(Optional<T[]> array); static Stream<T> flatten(Collection<Stream<T>> streams); static Stream<T> flatten(Stream<Stream<T>> streams); @SafeVarargs static Stream<T> flatten(Stream<T>... streams); static Stream<T> unfold(T seed, Function<T, Optional<T>> generator); static Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator); }
StreamUtils { public static <T> Stream<T> unfold(T seed, Function<T, Optional<T>> generator) { return StreamSupport.stream(new UnfoldSpliterator(seed, generator), !PARALLEL); }  @SafeVarargs static Stream<T> ofNullables(T... array); static Stream<T> ofNullable(T[] array); static Stream<T> ofOptional(Optional<T[]> array); static Stream<T> flatten(Collection<Stream<T>> streams); static Stream<T> flatten(Stream<Stream<T>> streams); @SafeVarargs static Stream<T> flatten(Stream<T>... streams); static Stream<T> unfold(T seed, Function<T, Optional<T>> generator); static Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator);  }