@Test void iterateWithANegativeLimitShouldThrow() { assertThatCode(() -> StreamUtils.iterate(1, (long) -1, Stream::of)) .isInstanceOf(IllegalArgumentException.class); }
public static <T> Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator) { Preconditions.checkArgument(limit >= 0, "StreamUtils.iterate have a given limit '{}', while it should not be negative", limit); return StreamUtils.unfold(Arrays.asList(seed), conservativeGenerator(generator)) .limit(limit + 1) .flatMap(List::stream); }
StreamUtils { public static <T> Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator) { Preconditions.checkArgument(limit >= 0, "StreamUtils.iterate have a given limit '{}', while it should not be negative", limit); return StreamUtils.unfold(Arrays.asList(seed), conservativeGenerator(generator)) .limit(limit + 1) .flatMap(List::stream); } }
StreamUtils { public static <T> Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator) { Preconditions.checkArgument(limit >= 0, "StreamUtils.iterate have a given limit '{}', while it should not be negative", limit); return StreamUtils.unfold(Arrays.asList(seed), conservativeGenerator(generator)) .limit(limit + 1) .flatMap(List::stream); }  }
StreamUtils { public static <T> Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator) { Preconditions.checkArgument(limit >= 0, "StreamUtils.iterate have a given limit '{}', while it should not be negative", limit); return StreamUtils.unfold(Arrays.asList(seed), conservativeGenerator(generator)) .limit(limit + 1) .flatMap(List::stream); }  @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> iterate(T seed, Long limit, Function<T, Stream<T>> generator) { Preconditions.checkArgument(limit >= 0, "StreamUtils.iterate have a given limit '{}', while it should not be negative", limit); return StreamUtils.unfold(Arrays.asList(seed), conservativeGenerator(generator)) .limit(limit + 1) .flatMap(List::stream); }  @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);  }