/** * Extends (continues) this {@code Stream} with values provided by a {@code Supplier} * * @param nextSupplier a supplier which will provide values for extending a stream * @return new {@code Stream} composed from this stream extended with values provided by the supplier */ default Stream<T> extend(Supplier<? extends T> nextSupplier) { Objects.requireNonNull(nextSupplier, "nextSupplier is null"); return Stream.ofAll(appendAll(Stream.continually(nextSupplier))); }
/** * Extends (continues) this {@code Stream} with a constantly repeated value. * * @param next value with which the stream should be extended * @return new {@code Stream} composed from this stream extended with a Stream of provided value */ default Stream<T> extend(T next) { return Stream.ofAll(this.appendAll(Stream.continually(next))); }
@Override default Stream<T> leftPadTo(int length, T element) { final int actualLength = length(); if (length <= actualLength) { return this; } else { return Stream.continually(element).take(length - actualLength).appendAll(this); } }
@Override default Stream<T> padTo(int length, T element) { if (length <= 0) { return this; } else if (isEmpty()) { return Stream.continually(element).take(length); } else { return cons(head(), () -> tail().padTo(length - 1, element)); } }
/** * Generates arbitrary streams based on a given element generator arbitraryT. * <p> * Example: * <pre> * <code> * Arbitrary.stream(Arbitrary.integer()); * </code> * </pre> * * @param arbitraryT Arbitrary elements of type T * @param <T> Component type of the Stream * @return a new Arbitrary of Stream<T> */ static <T> Arbitrary<Stream<T>> stream(Arbitrary<T> arbitraryT) { return size -> { final Gen<T> genT = arbitraryT.apply(size); return random -> Stream.continually(() -> genT.apply(random)) .take(Gen.choose(0, size).apply(random)); }; } }
/** * Extends (continues) this {@code Stream} with values provided by a {@code Supplier} * * @param nextSupplier a supplier which will provide values for extending a stream * @return new {@code Stream} composed from this stream extended with values provided by the supplier */ default Stream<T> extend(Supplier<? extends T> nextSupplier) { Objects.requireNonNull(nextSupplier, "nextSupplier is null"); return Stream.ofAll(appendAll(Stream.continually(nextSupplier))); }
/** * Extends (continues) this {@code Stream} with a constantly repeated value. * * @param next value with which the stream should be extended * @return new {@code Stream} composed from this stream extended with a Stream of provided value */ default Stream<T> extend(T next) { return Stream.ofAll(this.appendAll(Stream.continually(next))); }
@Override default Stream<T> leftPadTo(int length, T element) { final int actualLength = length(); if (length <= actualLength) { return this; } else { return Stream.continually(element).take(length - actualLength).appendAll(this); } }
@Override default Stream<T> padTo(int length, T element) { if (length <= 0) { return this; } else if (isEmpty()) { return Stream.continually(element).take(length); } else { return cons(head(), () -> tail().padTo(length - 1, element)); } }