### Question:
MoreStreams { public static <T> Stream<T> generate( T seed, Function<? super T, ? extends Stream<? extends T>> step) { requireNonNull(step); Queue<Stream<? extends T>> queue = new ArrayDeque<>(); queue.add(Stream.of(seed)); return whileNotNull(queue::poll) .flatMap(seeds -> withSideEffect( seeds, v -> { Stream<? extends T> fanout = step.apply(v); if (fanout != null) { queue.add(fanout); } })); } private  MoreStreams(); static Stream<T> generate(
      T seed, Function<? super T, ? extends Stream<? extends T>> step); static Stream<T> flatten(Stream<? extends Stream<? extends T>> streamOfStream); static Iterable<T> iterateOnce(Stream<T> stream); static void iterateThrough(
      Stream<? extends T> stream, CheckedConsumer<? super T, E> consumer); static Stream<List<T>> dice(Stream<? extends T> stream, int maxSize); static Spliterator<List<T>> dice(Spliterator<? extends T> spliterator, int maxSize); @Deprecated static Collector<Map<K, V>, ?, Map<K, V>> uniqueKeys(); static Collector<T, ?, R> flatMapping(
      Function<? super T, ? extends BiStream<? extends K, ? extends V>> flattener,
      BiCollector<K, V, R> downstream); @Deprecated static Collector<T, ?, R> flattening(
      Function<? super T, ? extends Collection<? extends Map.Entry<? extends K, ? extends V>>> flattener,
      BiCollector<K, V, R> downstream); static Collector<Map<K, V>, ?, R> flatteningMaps(
      BiCollector<K, V, R> downstream); static Collector<T, ?, List<T>> toListAndThen(Consumer<? super List<T>> arranger); static Stream<Integer> indexesFrom(int firstIndex); static Stream<T> whileNotNull(Supplier<? extends T> supplier); static Stream<T> withSideEffect(Stream<T> stream, Consumer<? super T> sideEffect); static Collector<T, ?, R> mapping(
      DualValuedFunction<? super T, ? extends K, ? extends V> mapper,
      BiCollector<K, V, R> downstream);  }### Answer:
@Test public void generateSingleElementStream() { assertThat(MoreStreams.generate(1, x -> Stream.empty()).collect(toList())) .containsExactly(1); }
@Test public void generate_functionReturnsNull() { assertThat(MoreStreams.generate(1, x -> null).collect(toList())) .containsExactly(1); }
@Test public void generateFanIn() throws Exception { assertThat(MoreStreams.generate(100, i -> IntStream.rangeClosed(1, i / 10).boxed()) .collect(toList())) .containsExactly(100, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1); }
@Test public void generateInfiniteStream() throws Exception { Stream<Integer> generated = MoreStreams.generate(1, i -> Stream.of(i + 1)); assertThat(generated.limit(10).collect(toList())) .containsExactly(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }