Interface Stream<T>

  • Type Parameters:
    T - component type of this Stream
    All Superinterfaces:
    Foldable<T>, java.util.function.Function<java.lang.Integer,​T>, Function1<java.lang.Integer,​T>, java.lang.Iterable<T>, LinearSeq<T>, PartialFunction<java.lang.Integer,​T>, Seq<T>, java.io.Serializable, Traversable<T>, Value<T>
    All Known Implementing Classes:
    Stream.Cons, Stream.Empty, StreamModule.AppendElements, StreamModule.ConsImpl

    public interface Stream<T>
    extends LinearSeq<T>
    An immutable Stream is lazy sequence of elements which may be infinitely long. Its immutability makes it suitable for concurrent programming.

    A Stream is composed of a head element and a lazy evaluated tail Stream.

    There are two implementations of the Stream interface:

    • Stream.Empty, which represents the empty Stream.
    • Stream.Cons, which represents a Stream containing one or more elements.
    Methods to obtain a Stream:
     
     // factory methods
     Stream.empty()                  // = Stream.of() = Empty.instance()
     Stream.of(x)                    // = new Cons<>(x, Empty.instance())
     Stream.of(Object...)            // e.g. Stream.of(1, 2, 3)
     Stream.ofAll(Iterable)          // e.g. Stream.ofAll(List.of(1, 2, 3)) = 1, 2, 3
     Stream.ofAll(<primitive array>) // e.g. List.ofAll(1, 2, 3) = 1, 2, 3
    
     // int sequences
     Stream.from(0)                  // = 0, 1, 2, 3, ...
     Stream.range(0, 3)              // = 0, 1, 2
     Stream.rangeClosed(0, 3)        // = 0, 1, 2, 3
    
     // generators
     Stream.cons(Object, Supplier)   // e.g. Stream.cons(current, () -> next(current));
     Stream.continually(Supplier)    // e.g. Stream.continually(Math::random);
     Stream.iterate(Object, Function)// e.g. Stream.iterate(1, i -> i * 2);
     
     
    Factory method applications:
     
     Stream<Integer>       s1 = Stream.of(1);
     Stream<Integer>       s2 = Stream.of(1, 2, 3);
                           // = Stream.of(new Integer[] {1, 2, 3});
    
     Stream<int[]>         s3 = Stream.ofAll(1, 2, 3);
     Stream<List<Integer>> s4 = Stream.ofAll(List.of(1, 2, 3));
    
     Stream<Integer>       s5 = Stream.ofAll(1, 2, 3);
     Stream<Integer>       s6 = Stream.ofAll(List.of(1, 2, 3));
    
     // cuckoo's egg
     Stream<Integer[]>     s7 = Stream.<Integer[]> of(new Integer[] {1, 2, 3});
     
     
    Example: Generating prime numbers
     
     // = Stream(2L, 3L, 5L, 7L, ...)
     Stream.iterate(2L, PrimeNumbers::nextPrimeFrom)
    
     // helpers
    
     static long nextPrimeFrom(long num) {
         return Stream.from(num + 1).find(PrimeNumbers::isPrime).get();
     }
    
     static boolean isPrime(long num) {
         return !Stream.rangeClosed(2L, (long) Math.sqrt(num)).exists(d -> num % d == 0);
     }
     
     
    See Okasaki, Chris: Purely Functional Data Structures (p. 34 ff.). Cambridge, 2003.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  Stream.Cons<T>
      Non-empty Stream, consisting of a head, and tail.
      static class  Stream.Empty<T>
      The empty Stream.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long serialVersionUID
      The serial version UID for serialization.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default Stream<T> append​(T element)
      Returns a new sequence with the given element appended at the end.
      default Stream<T> appendAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Returns a new sequence with all elements from the given Iterable appended at the end of this sequence.
      default Stream<T> appendSelf​(@NonNull java.util.function.Function<? super Stream<T>,​? extends Stream<T>> mapper)
      Appends itself to the end of stream with mapper function.
      default java.util.List<T> asJava()
      Returns an immutable List view of this Seq.
      default Stream<T> asJava​(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
      Creates an immutable List view of this Seq and passes it to the given action.
      default java.util.List<T> asJavaMutable()
      Returns a mutable List view of this Seq.
      default Stream<T> asJavaMutable​(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
      Creates a mutable List view of this Seq and passes it to the given action.
      default <R> Stream<R> collect​(@NonNull PartialFunction<? super T,​? extends R> partialFunction)
      Applies a PartialFunction to all elements that are defined for it and collects the results.
      static <T> java.util.stream.Collector<T,​java.util.ArrayList<T>,​Stream<T>> collector()
      Returns a Collector which may be used in conjunction with Stream.collect(java.util.stream.Collector) to obtain a Stream.
      default Stream<Stream<T>> combinations()
      Returns a sequence containing all combinations of elements from this sequence, for all sizes from 0 to length().
      default Stream<Stream<T>> combinations​(int k)
      Returns all subsets of this sequence containing exactly k distinct elements, i.e., the k-combinations of this sequence.
      static <T> Stream<T> concat​(@NonNull java.lang.Iterable<? extends java.lang.Iterable<? extends T>> iterables)
      Lazily creates a Stream in O(1) which traverses along the concatenation of the given iterables.
      static <T> Stream<T> concat​(@NonNull java.lang.Iterable<? extends T> @NonNull ... iterables)
      Lazily creates a Stream in O(1) which traverses along the concatenation of the given iterables.
      static <T> Stream<T> cons​(T head, @NonNull java.util.function.Supplier<? extends Stream<? extends T>> tailSupplier)
      Constructs a Stream of a head element and a tail supplier.
      static <T> Stream<T> continually​(@NonNull java.util.function.Supplier<? extends T> supplier)
      Generates an (theoretically) infinitely long Stream using a value Supplier.
      static <T> Stream<T> continually​(T t)
      Repeats an element infinitely often.
      default Iterator<Stream<T>> crossProduct​(int power)
      Returns the n-ary Cartesian power (cross product) of this sequence.
      default Stream<T> cycle()
      Repeat the elements of this Stream infinitely.
      default Stream<T> cycle​(int count)
      Repeat the elements of this Stream count times.
      default Stream<T> distinct()
      Returns a new Traversable containing the elements of this instance with all duplicates removed.
      default Stream<T> distinctBy​(@NonNull java.util.Comparator<? super T> comparator)
      Returns a new Traversable containing the elements of this instance without duplicates, as determined by the given comparator.
      default <U> Stream<T> distinctBy​(@NonNull java.util.function.Function<? super T,​? extends U> keyExtractor)
      Returns a new Traversable containing the elements of this instance without duplicates, based on keys extracted from elements using keyExtractor.
      default Stream<T> distinctByKeepLast​(@NonNull java.util.Comparator<? super T> comparator)
      Returns a sequence with duplicate elements removed, as determined by the provided comparator.
      default <U> Stream<T> distinctByKeepLast​(@NonNull java.util.function.Function<? super T,​? extends U> keyExtractor)
      Returns a sequence with duplicates removed based on a key extracted from each element.
      default Stream<T> drop​(int n)
      Returns a new Traversable without the first n elements, or an empty instance if this contains fewer than n elements.
      default Stream<T> dropRight​(int n)
      Returns a new Traversable without the last n elements, or an empty instance if this contains fewer than n elements.
      default Stream<T> dropRightUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
      Drops elements from the end of the sequence until an element satisfies the given predicate.
      default Stream<T> dropRightWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
      Drops elements from the end of the sequence while the given predicate holds.
      default Stream<T> dropUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
      Returns a new Traversable starting from the first element that satisfies the given predicate, dropping all preceding elements.
      default Stream<T> dropWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
      Returns a new Traversable starting from the first element that does not satisfy the given predicate, dropping all preceding elements.
      static <T> Stream<T> empty()
      Returns the single instance of Empty.
      default Stream<T> extend​(@NonNull java.util.function.Function<? super T,​? extends T> nextFunction)
      Extends (continues) this Stream with a Stream of values created by applying consecutively provided Function to the last element of the original Stream.
      default Stream<T> extend​(@NonNull java.util.function.Supplier<? extends T> nextSupplier)
      Extends (continues) this Stream with values provided by a Supplier
      default Stream<T> extend​(T next)
      Extends (continues) this Stream with a constantly repeated value.
      static <T> Stream<T> fill​(int n, @NonNull java.util.function.Supplier<? extends T> s)
      Returns a Stream containing n values supplied by a given Supplier s.
      static <T> Stream<T> fill​(int n, T element)
      Returns a Stream containing n times the given element
      default Stream<T> filter​(@NonNull java.util.function.Predicate<? super T> predicate)
      Returns a new traversable containing only the elements that satisfy the given predicate.
      default <U> Stream<U> flatMap​(@NonNull java.util.function.Function<? super T,​? extends java.lang.Iterable<? extends U>> mapper)
      Transforms each element of this Traversable into an Iterable of elements and flattens the resulting iterables into a single Traversable.
      static Stream<java.lang.Integer> from​(int value)
      Returns an infinitely long Stream of int values starting from from.
      static Stream<java.lang.Integer> from​(int value, int step)
      Returns an infinite long Stream of int values starting from value and spaced by step.
      static Stream<java.lang.Long> from​(long value)
      Returns an infinitely long Stream of long values starting from from.
      static Stream<java.lang.Long> from​(long value, long step)
      Returns an infinite long Stream of long values starting from value and spaced by step.
      default T get​(int index)
      Returns the element at the specified index.
      default <C> Map<C,​Stream<T>> groupBy​(@NonNull java.util.function.Function<? super T,​? extends C> classifier)
      Groups elements of this Traversable based on a classifier function.
      default Iterator<Stream<T>> grouped​(int size)
      Splits this Traversable into consecutive blocks of the given size.
      default boolean hasDefiniteSize()
      Indicates whether this Traversable has a known finite size.
      default int indexOf​(T element, int from)
      Returns the index of the first occurrence of the given element, starting at the specified index, or -1 if this sequence does not contain the element.
      default Stream<T> init()
      Returns all elements of this Traversable except the last one.
      default Option<Stream<T>> initOption()
      Returns all elements of this Traversable except the last one, wrapped in an Option.
      default Stream<T> insert​(int index, T element)
      Returns a new sequence with the given element inserted at the specified index.
      default Stream<T> insertAll​(int index, @NonNull java.lang.Iterable<? extends T> elements)
      Returns a new sequence with the given elements inserted at the specified index.
      default Stream<T> intersperse​(T element)
      Returns a new sequence where the given element is inserted between all elements of this sequence.
      default boolean isAsync()
      A Stream is computed synchronously.
      default boolean isLazy()
      A Stream is computed lazily.
      default boolean isTraversableAgain()
      Checks if this Traversable can be traversed multiple times without side effects.
      static <T> Stream<T> iterate​(@NonNull java.util.function.Supplier<? extends Option<? extends T>> supplier)
      Generates a (theoretically) infinitely long Stream using a repeatedly invoked supplier that provides a Some for each next value and a None for the end.
      static <T> Stream<T> iterate​(T seed, @NonNull java.util.function.Function<? super T,​? extends T> f)
      Generates a (theoretically) infinitely long Stream using a function to calculate the next value based on the previous.
      default T last()
      Returns the last element of this Traversable.
      default int lastIndexOf​(T element, int end)
      Returns the index of the last occurrence of the given element at or before the specified end index, or -1 if this sequence does not contain the element.
      default Stream<T> leftPadTo​(int length, T element)
      Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.
      default int length()
      Returns the number of elements in this Traversable.
      default <U> Stream<U> map​(@NonNull java.util.function.Function<? super T,​? extends U> mapper)
      Transforms the elements of this Traversable to a new type, preserving order if defined.
      default <U> Stream<U> mapTo​(U value)
      Maps the underlying value to another fixed value.
      default Stream<java.lang.Void> mapToVoid()
      Maps the underlying value to Void
      static <T> Stream<T> narrow​(Stream<? extends T> stream)
      Narrows a widened Stream<? extends T> to Stream<T> by performing a type-safe cast.
      static <T> Stream<T> of​(T element)
      Returns a singleton Stream, i.e.
      static <T> Stream<T> of​(T @NonNull ... elements)
      Creates a Stream of the given elements.
      static Stream<java.lang.Boolean> ofAll​(boolean @NonNull ... elements)
      Creates a Stream from boolean values.
      static Stream<java.lang.Byte> ofAll​(byte @NonNull ... elements)
      Creates a Stream from byte values.
      static Stream<java.lang.Character> ofAll​(char @NonNull ... elements)
      Creates a Stream from char values.
      static Stream<java.lang.Double> ofAll​(double @NonNull ... elements)
      Creates a Stream values double values.
      static Stream<java.lang.Float> ofAll​(float @NonNull ... elements)
      Creates a Stream from float values.
      static Stream<java.lang.Integer> ofAll​(int @NonNull ... elements)
      Creates a Stream from int values.
      static Stream<java.lang.Long> ofAll​(long @NonNull ... elements)
      Creates a Stream from long values.
      static Stream<java.lang.Short> ofAll​(short @NonNull ... elements)
      Creates a Stream from short values.
      static <T> Stream<T> ofAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Creates a Stream of the given elements.
      static <T> Stream<T> ofAll​(@NonNull java.util.stream.Stream<? extends T> javaStream)
      Creates a Stream that contains the elements of the given Stream.
      default Stream<T> orElse​(@NonNull java.lang.Iterable<? extends T> other)
      Returns this Traversable if it is non-empty; otherwise, returns the given alternative.
      default Stream<T> orElse​(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
      Returns this Traversable if it is non-empty; otherwise, returns the result of evaluating the given supplier.
      default Stream<T> padTo​(int length, T element)
      Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.
      default Tuple2<Stream<T>,​Stream<T>> partition​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this Traversable into two partitions according to a predicate.
      default Stream<T> patch​(int from, @NonNull java.lang.Iterable<? extends T> that, int replaced)
      Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.
      default Stream<T> peek​(@NonNull java.util.function.Consumer<? super T> action)
      Performs the given action on the first element if this is an eager implementation.
      default Stream<Stream<T>> permutations()
      Returns all unique permutations of this sequence.
      default Stream<T> prepend​(T element)
      Returns a new sequence with the given element prepended to this sequence.
      default Stream<T> prependAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Returns a new sequence with all given elements prepended to this sequence.
      static Stream<java.lang.Character> range​(char from, char toExclusive)
      Creates a Stream of char numbers starting from from, extending to toExclusive - 1.
      static Stream<java.lang.Integer> range​(int from, int toExclusive)
      Creates a Stream of int numbers starting from from, extending to toExclusive - 1.
      static Stream<java.lang.Long> range​(long from, long toExclusive)
      Creates a Stream of long numbers starting from from, extending to toExclusive - 1.
      static Stream<java.lang.Character> rangeBy​(char from, char toExclusive, int step)
      Creates a Stream of char numbers starting from from, extending to toExclusive - 1, with step.
      static Stream<java.lang.Double> rangeBy​(double from, double toExclusive, double step)
      Creates a Stream of double numbers starting from from, extending up to but not including toExclusive, with step.
      static Stream<java.lang.Integer> rangeBy​(int from, int toExclusive, int step)
      Creates a Stream of int numbers starting from from, extending to toExclusive - 1, with step.
      static Stream<java.lang.Long> rangeBy​(long from, long toExclusive, long step)
      Creates a Stream of long numbers starting from from, extending to toExclusive - 1, with step.
      static Stream<java.lang.Character> rangeClosed​(char from, char toInclusive)
      Creates a Stream of char numbers starting from from, extending to toInclusive.
      static Stream<java.lang.Integer> rangeClosed​(int from, int toInclusive)
      Creates a Stream of int numbers starting from from, extending to toInclusive.
      static Stream<java.lang.Long> rangeClosed​(long from, long toInclusive)
      Creates a Stream of long numbers starting from from, extending to toInclusive.
      static Stream<java.lang.Character> rangeClosedBy​(char from, char toInclusive, int step)
      Creates a Stream of char values starting from from, extending to toInclusive, with step.
      static Stream<java.lang.Double> rangeClosedBy​(double from, double toInclusive, double step)
      Creates a Stream of double values starting from from, extending to toInclusive, with step.
      static Stream<java.lang.Integer> rangeClosedBy​(int from, int toInclusive, int step)
      Creates a Stream of int numbers starting from from, extending to toInclusive, with step.
      static Stream<java.lang.Long> rangeClosedBy​(long from, long toInclusive, long step)
      Creates a Stream of long numbers starting from from, extending to toInclusive, with step.
      default Stream<T> reject​(@NonNull java.util.function.Predicate<? super T> predicate)
      Returns a new traversable containing only the elements that do not satisfy the given predicate.
      default Stream<T> remove​(T element)
      Returns a new sequence with the first occurrence of the given element removed.
      default Stream<T> removeAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Returns a new sequence with all occurrences of the given elements removed.
      default Stream<T> removeAll​(@NonNull java.util.function.Predicate<? super T> predicate)
      Deprecated.
      default Stream<T> removeAll​(T element)
      Returns a new sequence with all occurrences of the given element removed.
      default Stream<T> removeAt​(int index)
      Returns a new sequence with the element at the specified position removed.
      default Stream<T> removeFirst​(@NonNull java.util.function.Predicate<T> predicate)
      Returns a new sequence with the first element that satisfies the given predicate removed.
      default Stream<T> removeLast​(@NonNull java.util.function.Predicate<T> predicate)
      Returns a new sequence with the last element that satisfies the given predicate removed.
      default Stream<T> replace​(T currentElement, T newElement)
      Replaces the first occurrence of currentElement with newElement, if it exists.
      default Stream<T> replaceAll​(T currentElement, T newElement)
      Replaces all occurrences of currentElement with newElement.
      default Stream<T> retainAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Retains only the elements from this Traversable that are contained in the given elements.
      default Stream<T> reverse()
      Returns a new sequence with the order of elements reversed.
      default Stream<T> rotateLeft​(int n)
      Returns a new sequence with the elements circularly rotated to the left by the specified distance.
      default Stream<T> rotateRight​(int n)
      Returns a new sequence with the elements circularly rotated to the right by the specified distance.
      default Stream<T> scan​(T zero, @NonNull java.util.function.BiFunction<? super T,​? super T,​? extends T> operation)
      Computes a prefix scan of the elements of this Traversable.
      default <U> Stream<U> scanLeft​(U zero, @NonNull java.util.function.BiFunction<? super U,​? super T,​? extends U> operation)
      Produces a collection containing cumulative results of applying the operator from left to right.
      default <U> Stream<U> scanRight​(U zero, @NonNull java.util.function.BiFunction<? super T,​? super U,​? extends U> operation)
      Produces a collection containing cumulative results of applying the operator from right to left.
      default Stream<T> shuffle()
      Returns a new sequence with the elements randomly shuffled.
      default Stream<T> slice​(int beginIndex, int endIndex)
      Returns a subsequence (slice) of this sequence, starting at beginIndex (inclusive) and ending at endIndex (exclusive).
      default Iterator<Stream<T>> slideBy​(@NonNull java.util.function.Function<? super T,​?> classifier)
      Partitions this Traversable into consecutive non-overlapping windows according to a classification function.
      default Iterator<Stream<T>> sliding​(int size)
      Slides a window of a given size over this Traversable with a step size of 1.
      default Iterator<Stream<T>> sliding​(int size, int step)
      Slides a window of a specific size with a given step over this Traversable.
      default <U> Stream<T> sortBy​(@NonNull java.util.Comparator<? super U> comparator, java.util.function.Function<? super T,​? extends U> mapper)
      Returns a new sequence sorted by comparing elements in a different domain defined by the given mapper, using the provided comparator.
      default <U extends java.lang.Comparable<? super U>>
      Stream<T>
      sortBy​(@NonNull java.util.function.Function<? super T,​? extends U> mapper)
      Returns a new sequence sorted by comparing elements in a different domain defined by the given mapper.
      default Stream<T> sorted()
      Returns a new sequence with elements sorted according to their natural order.
      default Stream<T> sorted​(@NonNull java.util.Comparator<? super T> comparator)
      Returns a new sequence with elements sorted according to the given Comparator.
      default Tuple2<Stream<T>,​Stream<T>> span​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this Traversable into a prefix and remainder according to the given predicate.
      default Tuple2<Stream<T>,​Stream<T>> splitAt​(int n)
      Splits this sequence at the specified index.
      default Tuple2<Stream<T>,​Stream<T>> splitAt​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this sequence at the first element satisfying the given predicate.
      default Tuple2<Stream<T>,​Stream<T>> splitAtInclusive​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this sequence at the first element satisfying the given predicate, including the element in the first part.
      default java.lang.String stringPrefix()
      Returns the name of this Value type, which is used by toString().
      default Stream<T> subSequence​(int beginIndex)
      Returns a Seq that is a subsequence of this sequence, starting from the specified beginIndex and extending to the end of this sequence.
      default Stream<T> subSequence​(int beginIndex, int endIndex)
      Returns a Seq that is a subsequence of this sequence, starting from the specified beginIndex (inclusive) and ending at endIndex (exclusive).
      static <T> Stream<T> tabulate​(int n, @NonNull java.util.function.Function<? super java.lang.Integer,​? extends T> f)
      Returns a Stream containing n values of a given Function f over a range of integer values from 0 to n - 1.
      Stream<T> tail()
      Returns a new Traversable without its first element.
      default Option<Stream<T>> tailOption()
      Returns a new Traversable without its first element as an Option.
      default Stream<T> take​(int n)
      Returns the first n elements of this Traversable, or all elements if n exceeds the length.
      default Stream<T> takeRight​(int n)
      Returns the last n elements of this Traversable, or all elements if n exceeds the length.
      default Stream<T> takeRightUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from the end of the sequence until an element satisfies the given predicate.
      default Stream<T> takeRightWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from the end of the sequence while the given predicate holds.
      default Stream<T> takeUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from this Traversable until the given predicate holds for an element.
      default Stream<T> takeWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from this Traversable while the given predicate holds.
      default <U> U transform​(@NonNull java.util.function.Function<? super Stream<T>,​? extends U> f)
      Transforms this Stream.
      static <T> Stream<Stream<T>> transpose​(@NonNull Stream<Stream<T>> matrix)
      Transposes the rows and columns of a Stream matrix.
      static <T> Stream<T> unfold​(T seed, @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends T,​? extends T>>> f)
      Creates a Stream from a seed value and a function.
      static <T,​U>
      Stream<U>
      unfoldLeft​(T seed, @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends T,​? extends U>>> f)
      Creates a Stream from a seed value and a function.
      static <T,​U>
      Stream<U>
      unfoldRight​(T seed, @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends U,​? extends T>>> f)
      Creates a Stream from a seed value and a function.
      default <T1,​T2>
      Tuple2<Stream<T1>,​Stream<T2>>
      unzip​(@NonNull java.util.function.Function<? super T,​Tuple2<? extends T1,​? extends T2>> unzipper)
      Unzips the elements of this Traversable by mapping each element to a pair and splitting them into two separate Traversable collections.
      default <T1,​T2,​T3>
      Tuple3<Stream<T1>,​Stream<T2>,​Stream<T3>>
      unzip3​(@NonNull java.util.function.Function<? super T,​Tuple3<? extends T1,​? extends T2,​? extends T3>> unzipper)
      Unzips the elements of this Traversable by mapping each element to a triple and splitting them into three separate Traversable collections.
      default Stream<T> update​(int index, @NonNull java.util.function.Function<? super T,​? extends T> updater)
      Returns a new Seq with the element at the specified index updated using the given function.
      default Stream<T> update​(int index, T element)
      Returns a new Seq with the element at the specified index replaced by the given value.
      default <U> Stream<Tuple2<T,​U>> zip​(@NonNull java.lang.Iterable<? extends U> that)
      Returns a Traversable formed by pairing elements of this Traversable with elements of another Iterable.
      default <U> Stream<Tuple2<T,​U>> zipAll​(@NonNull java.lang.Iterable<? extends U> iterable, T thisElem, U thatElem)
      Returns a Traversable formed by pairing elements of this Traversable with elements of another Iterable, filling in placeholder elements when one collection is shorter than the other.
      default <U,​R>
      Stream<R>
      zipWith​(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,​? super U,​? extends R> mapper)
      Returns a Traversable by combining elements of this Traversable with elements of another Iterable using a mapping function.
      default Stream<Tuple2<T,​java.lang.Integer>> zipWithIndex()
      Zips this Traversable with its indices, starting at 0.
      default <U> Stream<U> zipWithIndex​(@NonNull java.util.function.BiFunction<? super T,​? super java.lang.Integer,​? extends U> mapper)
      Zips this Traversable with its indices and maps the resulting pairs using the provided mapper.
    • Field Detail

      • serialVersionUID

        static final long serialVersionUID
        The serial version UID for serialization.
        See Also:
        Constant Field Values
    • Method Detail

      • collector

        static <T> java.util.stream.Collector<T,​java.util.ArrayList<T>,​Stream<T>> collector()
        Returns a Collector which may be used in conjunction with Stream.collect(java.util.stream.Collector) to obtain a Stream.
        Type Parameters:
        T - Component type of the Stream.
        Returns:
        A io.vavr.collection.Stream Collector.
      • concat

        @SafeVarargs
        static <T> Stream<T> concat​(@NonNull java.lang.Iterable<? extends T> @NonNull ... iterables)
        Lazily creates a Stream in O(1) which traverses along the concatenation of the given iterables.
        Type Parameters:
        T - Component type.
        Parameters:
        iterables - The iterables
        Returns:
        A new Stream
      • concat

        static <T> Stream<T> concat​(@NonNull java.lang.Iterable<? extends java.lang.Iterable<? extends T>> iterables)
        Lazily creates a Stream in O(1) which traverses along the concatenation of the given iterables.
        Type Parameters:
        T - Component type.
        Parameters:
        iterables - The iterable of iterables
        Returns:
        A new Stream
      • from

        static Stream<java.lang.Integer> from​(int value)
        Returns an infinitely long Stream of int values starting from from.

        The Stream extends to Integer.MIN_VALUE when passing Integer.MAX_VALUE.

        Parameters:
        value - a start int value
        Returns:
        a new Stream of int values starting from from
      • from

        static Stream<java.lang.Integer> from​(int value,
                                              int step)
        Returns an infinite long Stream of int values starting from value and spaced by step.

        The Stream extends to Integer.MIN_VALUE when passing Integer.MAX_VALUE.

        Parameters:
        value - a start int value
        step - the step by which to advance on each next value
        Returns:
        a new Stream of int values starting from from
      • from

        static Stream<java.lang.Long> from​(long value)
        Returns an infinitely long Stream of long values starting from from.

        The Stream extends to Integer.MIN_VALUE when passing Long.MAX_VALUE.

        Parameters:
        value - a start long value
        Returns:
        a new Stream of long values starting from from
      • from

        static Stream<java.lang.Long> from​(long value,
                                           long step)
        Returns an infinite long Stream of long values starting from value and spaced by step.

        The Stream extends to Long.MIN_VALUE when passing Long.MAX_VALUE.

        Parameters:
        value - a start long value
        step - the step by which to advance on each next value
        Returns:
        a new Stream of long values starting from from
      • continually

        static <T> Stream<T> continually​(@NonNull java.util.function.Supplier<? extends T> supplier)
        Generates an (theoretically) infinitely long Stream using a value Supplier.
        Type Parameters:
        T - value type
        Parameters:
        supplier - A Supplier of Stream values
        Returns:
        A new Stream
      • iterate

        static <T> Stream<T> iterate​(T seed,
                                     @NonNull java.util.function.Function<? super T,​? extends T> f)
        Generates a (theoretically) infinitely long Stream using a function to calculate the next value based on the previous.
        Type Parameters:
        T - value type
        Parameters:
        seed - The first value in the Stream
        f - A function to calculate the next value based on the previous
        Returns:
        A new Stream
      • iterate

        static <T> Stream<T> iterate​(@NonNull java.util.function.Supplier<? extends Option<? extends T>> supplier)
        Generates a (theoretically) infinitely long Stream using a repeatedly invoked supplier that provides a Some for each next value and a None for the end. The Supplier will be invoked only that many times until it returns None, and repeated iteration over the stream will produce the same values in the same order, without any further invocations to the Supplier.
        Type Parameters:
        T - value type
        Parameters:
        supplier - A Supplier of iterator values
        Returns:
        A new Stream
      • cons

        static <T> Stream<T> cons​(T head,
                                  @NonNull java.util.function.Supplier<? extends Stream<? extends T>> tailSupplier)
        Constructs a Stream of a head element and a tail supplier.
        Type Parameters:
        T - value type
        Parameters:
        head - The head element of the Stream
        tailSupplier - A supplier of the tail values. To end the stream, return empty().
        Returns:
        A new Stream
      • empty

        static <T> Stream<T> empty()
        Returns the single instance of Empty. Convenience method for Empty.instance().

        Note: this method intentionally returns type Stream and not Empty. This comes in handy when folding. If you explicitly need type Empty use Stream.Empty.instance().

        Type Parameters:
        T - Component type of Empty, determined by type inference in the particular context.
        Returns:
        The empty list.
      • narrow

        static <T> Stream<T> narrow​(Stream<? extends T> stream)
        Narrows a widened Stream<? extends T> to Stream<T> by performing a type-safe cast. This is eligible because immutable/read-only collections are covariant.
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        stream - A Stream.
        Returns:
        the given stream instance as narrowed type Stream<T>.
      • of

        static <T> Stream<T> of​(T element)
        Returns a singleton Stream, i.e. a Stream of one element.
        Type Parameters:
        T - The component type
        Parameters:
        element - An element.
        Returns:
        A new Stream instance containing the given element
      • of

        @SafeVarargs
        static <T> Stream<T> of​(T @NonNull ... elements)
        Creates a Stream of the given elements.
         Stream.of(1, 2, 3, 4)
         = Empty.instance().prepend(4).prepend(3).prepend(2).prepend(1)
         = new Cons(1, new Cons(2, new Cons(3, new Cons(4, Empty.instance()))))
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        elements - Zero or more elements.
        Returns:
        A list containing the given elements in the same order.
      • tabulate

        static <T> Stream<T> tabulate​(int n,
                                      @NonNull java.util.function.Function<? super java.lang.Integer,​? extends T> f)
        Returns a Stream containing n values of a given Function f over a range of integer values from 0 to n - 1.
        Type Parameters:
        T - Component type of the Stream
        Parameters:
        n - The number of elements in the Stream
        f - The Function computing element values
        Returns:
        A Stream consisting of elements f(0),f(1), ..., f(n - 1)
        Throws:
        java.lang.NullPointerException - if f is null
      • fill

        static <T> Stream<T> fill​(int n,
                                  @NonNull java.util.function.Supplier<? extends T> s)
        Returns a Stream containing n values supplied by a given Supplier s.
        Type Parameters:
        T - Component type of the Stream
        Parameters:
        n - The number of elements in the Stream
        s - The Supplier computing element values
        Returns:
        A Stream of size n, where each element contains the result supplied by s.
        Throws:
        java.lang.NullPointerException - if s is null
      • fill

        static <T> Stream<T> fill​(int n,
                                  T element)
        Returns a Stream containing n times the given element
        Type Parameters:
        T - Component type of the Stream
        Parameters:
        n - The number of elements in the Stream
        element - The element
        Returns:
        A Stream of size n, where each element is the given element.
      • ofAll

        static <T> Stream<T> ofAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Creates a Stream of the given elements.
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        elements - An Iterable of elements.
        Returns:
        A Stream containing the given elements in the same order.
      • ofAll

        static <T> Stream<T> ofAll​(@NonNull java.util.stream.Stream<? extends T> javaStream)
        Creates a Stream that contains the elements of the given Stream.
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        javaStream - A Stream
        Returns:
        A Stream containing the given elements in the same order.
      • ofAll

        static Stream<java.lang.Boolean> ofAll​(boolean @NonNull ... elements)
        Creates a Stream from boolean values.
        Parameters:
        elements - boolean values
        Returns:
        A new Stream of Boolean values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Byte> ofAll​(byte @NonNull ... elements)
        Creates a Stream from byte values.
        Parameters:
        elements - byte values
        Returns:
        A new Stream of Byte values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Character> ofAll​(char @NonNull ... elements)
        Creates a Stream from char values.
        Parameters:
        elements - char values
        Returns:
        A new Stream of Character values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Double> ofAll​(double @NonNull ... elements)
        Creates a Stream values double values.
        Parameters:
        elements - double values
        Returns:
        A new Stream of Double values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Float> ofAll​(float @NonNull ... elements)
        Creates a Stream from float values.
        Parameters:
        elements - float values
        Returns:
        A new Stream of Float values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Integer> ofAll​(int @NonNull ... elements)
        Creates a Stream from int values.
        Parameters:
        elements - int values
        Returns:
        A new Stream of Integer values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Long> ofAll​(long @NonNull ... elements)
        Creates a Stream from long values.
        Parameters:
        elements - long values
        Returns:
        A new Stream of Long values
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        static Stream<java.lang.Short> ofAll​(short @NonNull ... elements)
        Creates a Stream from short values.
        Parameters:
        elements - short values
        Returns:
        A new Stream of Short values
        Throws:
        java.lang.NullPointerException - if elements is null
      • range

        static Stream<java.lang.Character> range​(char from,
                                                 char toExclusive)
        Creates a Stream of char numbers starting from from, extending to toExclusive - 1.

        Examples:

         
         Stream.range('a', 'a')  // = Stream()
         Stream.range('c', 'a')  // = Stream()
         Stream.range('a', 'd')  // = Stream('a', 'b', 'c')
         
         
        Parameters:
        from - the first char
        toExclusive - the last char + 1
        Returns:
        a range of char values as specified or Nil if from >= toExclusive
      • rangeBy

        static Stream<java.lang.Character> rangeBy​(char from,
                                                   char toExclusive,
                                                   int step)
        Creates a Stream of char numbers starting from from, extending to toExclusive - 1, with step.

        Examples:

         
         Stream.rangeBy('a', 'c', 1)  // = Stream('a', 'b')
         Stream.rangeBy('a', 'd', 2)  // = Stream('a', 'c')
         Stream.rangeBy('d', 'a', -2) // = Stream('d', 'b')
         Stream.rangeBy('d', 'a', 2)  // = Stream()
         
         
        Parameters:
        from - the first char
        toExclusive - the last char + 1
        step - the step
        Returns:
        a range of char values as specified or Nil if
        from >= toExclusive and step > 0 or
        from <= toExclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeBy

        @GwtIncompatible
        static Stream<java.lang.Double> rangeBy​(double from,
                                                double toExclusive,
                                                double step)
        Creates a Stream of double numbers starting from from, extending up to but not including toExclusive, with step.

        Examples:

         
         Stream.rangeBy(1.0, 3.0, 1.0)  // = Stream(1.0, 2.0)
         Stream.rangeBy(1.0, 4.0, 2.0)  // = Stream(1.0, 3.0)
         Stream.rangeBy(4.0, 1.0, -2.0) // = Stream(4.0, 2.0)
         Stream.rangeBy(4.0, 1.0, 2.0)  // = Stream()
         
         
        Parameters:
        from - the first double
        toExclusive - the upper bound (exclusive)
        step - the step
        Returns:
        a range of double values as specified or Nil if
        from >= toExclusive and step > 0 or
        from <= toExclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • range

        static Stream<java.lang.Integer> range​(int from,
                                               int toExclusive)
        Creates a Stream of int numbers starting from from, extending to toExclusive - 1.

        Examples:

         
         Stream.range(0, 0)  // = Stream()
         Stream.range(2, 0)  // = Stream()
         Stream.range(-2, 2) // = Stream(-2, -1, 0, 1)
         
         
        Parameters:
        from - the first number
        toExclusive - the last number + 1
        Returns:
        a range of int values as specified or Nil if from >= toExclusive
      • rangeBy

        static Stream<java.lang.Integer> rangeBy​(int from,
                                                 int toExclusive,
                                                 int step)
        Creates a Stream of int numbers starting from from, extending to toExclusive - 1, with step.

        Examples:

         
         Stream.rangeBy(1, 3, 1)  // = Stream(1, 2)
         Stream.rangeBy(1, 4, 2)  // = Stream(1, 3)
         Stream.rangeBy(4, 1, -2) // = Stream(4, 2)
         Stream.rangeBy(4, 1, 2)  // = Stream()
         
         
        Parameters:
        from - the first number
        toExclusive - the last number + 1
        step - the step
        Returns:
        a range of long values as specified or Nil if
        from >= toInclusive and step > 0 or
        from <= toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • range

        static Stream<java.lang.Long> range​(long from,
                                            long toExclusive)
        Creates a Stream of long numbers starting from from, extending to toExclusive - 1.

        Examples:

         
         Stream.range(0L, 0L)  // = Stream()
         Stream.range(2L, 0L)  // = Stream()
         Stream.range(-2L, 2L) // = Stream(-2L, -1L, 0L, 1L)
         
         
        Parameters:
        from - the first number
        toExclusive - the last number + 1
        Returns:
        a range of long values as specified or Nil if from >= toExclusive
      • rangeBy

        static Stream<java.lang.Long> rangeBy​(long from,
                                              long toExclusive,
                                              long step)
        Creates a Stream of long numbers starting from from, extending to toExclusive - 1, with step.

        Examples:

         
         Stream.rangeBy(1L, 3L, 1L)  // = Stream(1L, 2L)
         Stream.rangeBy(1L, 4L, 2L)  // = Stream(1L, 3L)
         Stream.rangeBy(4L, 1L, -2L) // = Stream(4L, 2L)
         Stream.rangeBy(4L, 1L, 2L)  // = Stream()
         
         
        Parameters:
        from - the first number
        toExclusive - the last number + 1
        step - the step
        Returns:
        a range of long values as specified or Nil if
        from >= toInclusive and step > 0 or
        from <= toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeClosed

        static Stream<java.lang.Character> rangeClosed​(char from,
                                                       char toInclusive)
        Creates a Stream of char numbers starting from from, extending to toInclusive.

        Examples:

         
         Stream.rangeClosed('a', 'a')  // = Stream('a')
         Stream.rangeClosed('c', 'a')  // = Stream()
         Stream.rangeClosed('a', 'd')  // = Stream('a', 'b', 'c', 'd')
         
         
        Parameters:
        from - the first char
        toInclusive - the last char
        Returns:
        a range of char values as specified or Nil if from > toInclusive
      • rangeClosedBy

        static Stream<java.lang.Character> rangeClosedBy​(char from,
                                                         char toInclusive,
                                                         int step)
        Creates a Stream of char values starting from from, extending to toInclusive, with step.
        Parameters:
        from - the first char
        toInclusive - the last char (inclusive)
        step - the step
        Returns:
        a range of char values as specified or Nil if
        from >= toInclusive and step > 0 or
        from <= toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeClosedBy

        @GwtIncompatible
        static Stream<java.lang.Double> rangeClosedBy​(double from,
                                                      double toInclusive,
                                                      double step)
        Creates a Stream of double values starting from from, extending to toInclusive, with step.
        Parameters:
        from - the first double
        toInclusive - the last double (inclusive)
        step - the step
        Returns:
        a range of double values as specified or Nil if
        from >= toInclusive and step > 0 or
        from <= toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeClosed

        static Stream<java.lang.Integer> rangeClosed​(int from,
                                                     int toInclusive)
        Creates a Stream of int numbers starting from from, extending to toInclusive.

        Examples:

         
         Stream.rangeClosed(0, 0)  // = Stream(0)
         Stream.rangeClosed(2, 0)  // = Stream()
         Stream.rangeClosed(-2, 2) // = Stream(-2, -1, 0, 1, 2)
         
         
        Parameters:
        from - the first number
        toInclusive - the last number
        Returns:
        a range of int values as specified or Nil if from > toInclusive
      • rangeClosedBy

        static Stream<java.lang.Integer> rangeClosedBy​(int from,
                                                       int toInclusive,
                                                       int step)
        Creates a Stream of int numbers starting from from, extending to toInclusive, with step.

        Examples:

         
         Stream.rangeClosedBy(1, 3, 1)  // = Stream(1, 2, 3)
         Stream.rangeClosedBy(1, 4, 2)  // = Stream(1, 3)
         Stream.rangeClosedBy(4, 1, -2) // = Stream(4, 2)
         Stream.rangeClosedBy(4, 1, 2)  // = Stream()
         
         
        Parameters:
        from - the first number
        toInclusive - the last number
        step - the step
        Returns:
        a range of int values as specified or Nil if
        from > toInclusive and step > 0 or
        from < toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeClosed

        static Stream<java.lang.Long> rangeClosed​(long from,
                                                  long toInclusive)
        Creates a Stream of long numbers starting from from, extending to toInclusive.

        Examples:

         
         Stream.rangeClosed(0L, 0L)  // = Stream(0L)
         Stream.rangeClosed(2L, 0L)  // = Stream()
         Stream.rangeClosed(-2L, 2L) // = Stream(-2L, -1L, 0L, 1L, 2L)
         
         
        Parameters:
        from - the first number
        toInclusive - the last number
        Returns:
        a range of long values as specified or Nil if from > toInclusive
      • rangeClosedBy

        static Stream<java.lang.Long> rangeClosedBy​(long from,
                                                    long toInclusive,
                                                    long step)
        Creates a Stream of long numbers starting from from, extending to toInclusive, with step.

        Examples:

         
         Stream.rangeClosedBy(1L, 3L, 1L)  // = Stream(1L, 2L, 3L)
         Stream.rangeClosedBy(1L, 4L, 2L)  // = Stream(1L, 3L)
         Stream.rangeClosedBy(4L, 1L, -2L) // = Stream(4L, 2L)
         Stream.rangeClosedBy(4L, 1L, 2L)  // = Stream()
         
         
        Parameters:
        from - the first number
        toInclusive - the last number
        step - the step
        Returns:
        a range of int values as specified or Nil if
        from > toInclusive and step > 0 or
        from < toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • transpose

        static <T> Stream<Stream<T>> transpose​(@NonNull Stream<Stream<T>> matrix)
        Transposes the rows and columns of a Stream matrix.
        Type Parameters:
        T - matrix element type
        Parameters:
        matrix - to be transposed.
        Returns:
        a transposed Stream matrix.
        Throws:
        java.lang.IllegalArgumentException - if the row lengths of matrix differ.

        ex: Stream.transpose(Stream(Stream(1,2,3), Stream(4,5,6))) → Stream(Stream(1,4), Stream(2,5), Stream(3,6))

      • unfoldRight

        static <T,​U> Stream<U> unfoldRight​(T seed,
                                                 @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends U,​? extends T>>> f)
        Creates a Stream from a seed value and a function. The function takes the seed at first. The function should return None when it's done generating the Stream, otherwise Some Tuple of the element for the next call and the value to add to the resulting Stream.

        Example:

         
         Stream.unfoldRight(10, x -> x == 0
                     ? Option.none()
                     : Option.of(new Tuple2<>(x, x-1)));
         // Stream(10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
         
         
        Type Parameters:
        T - type of seeds
        U - type of unfolded values
        Parameters:
        seed - the start value for the iteration
        f - the function to get the next step of the iteration
        Returns:
        a Stream with the values built up by the iteration
        Throws:
        java.lang.NullPointerException - if f is null
      • unfoldLeft

        static <T,​U> Stream<U> unfoldLeft​(T seed,
                                                @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends T,​? extends U>>> f)
        Creates a Stream from a seed value and a function. The function takes the seed at first. The function should return None when it's done generating the Stream, otherwise Some Tuple of the value to add to the resulting Stream and the element for the next call.

        Example:

         
         Stream.unfoldLeft(10, x -> x == 0
                     ? Option.none()
                     : Option.of(new Tuple2<>(x-1, x)));
         // Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
         
         
        Type Parameters:
        T - type of seeds
        U - type of unfolded values
        Parameters:
        seed - the start value for the iteration
        f - the function to get the next step of the iteration
        Returns:
        a Stream with the values built up by the iteration
        Throws:
        java.lang.NullPointerException - if f is null
      • unfold

        static <T> Stream<T> unfold​(T seed,
                                    @NonNull java.util.function.Function<? super T,​Option<Tuple2<? extends T,​? extends T>>> f)
        Creates a Stream from a seed value and a function. The function takes the seed at first. The function should return None when it's done generating the Stream, otherwise Some Tuple of the value to add to the resulting Stream and the element for the next call.

        Example:

         
         Stream.unfold(10, x -> x == 0
                     ? Option.none()
                     : Option.of(new Tuple2<>(x-1, x)));
         // Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
         
         
        Type Parameters:
        T - type of seeds and unfolded values
        Parameters:
        seed - the start value for the iteration
        f - the function to get the next step of the iteration
        Returns:
        a Stream with the values built up by the iteration
        Throws:
        java.lang.NullPointerException - if f is null
      • continually

        static <T> Stream<T> continually​(T t)
        Repeats an element infinitely often.
        Type Parameters:
        T - Element type
        Parameters:
        t - An element
        Returns:
        A new Stream containing infinite t's.
      • append

        default Stream<T> append​(T element)
        Description copied from interface: Seq
        Returns a new sequence with the given element appended at the end.
        Specified by:
        append in interface LinearSeq<T>
        Specified by:
        append in interface Seq<T>
        Parameters:
        element - the element to append
        Returns:
        a new Seq containing all elements of this sequence followed by the given element
      • appendAll

        default Stream<T> appendAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Seq
        Returns a new sequence with all elements from the given Iterable appended at the end of this sequence.
        Specified by:
        appendAll in interface LinearSeq<T>
        Specified by:
        appendAll in interface Seq<T>
        Parameters:
        elements - the elements to append; must not be null
        Returns:
        a new Seq containing all elements of this sequence followed by the given elements
      • appendSelf

        default Stream<T> appendSelf​(@NonNull java.util.function.Function<? super Stream<T>,​? extends Stream<T>> mapper)
        Appends itself to the end of stream with mapper function.

        Example:

        Well known Scala code for Fibonacci infinite sequence

         
         val fibs:Stream[Int] = 0 #:: 1 #:: (fibs zip fibs.tail).map{ t => t._1 + t._2 }
         
         
        can be transformed to
         
         Stream.of(0, 1).appendSelf(self -> self.zip(self.tail()).map(t -> t._1 + t._2));
         
         
        Parameters:
        mapper - an mapper
        Returns:
        a new Stream
      • asJava

        @GwtIncompatible
        default java.util.List<T> asJava()
        Description copied from interface: Seq
        Returns an immutable List view of this Seq. Any attempt to modify the view (e.g., via mutator methods) will throw UnsupportedOperationException at runtime.

        This is a view, not a copy. Compared to conversion methods like toJava*():

        • Creating the view is O(1) (constant time), whereas conversions take O(n), with n = collection size.
        • Operations on the view have the same performance characteristics as the underlying persistent Vavr collection, while converted collections behave like standard Java collections.

        Note: the immutable Java list view throws UnsupportedOperationException before checking method arguments, which may differ from standard Java behavior.

        Specified by:
        asJava in interface Seq<T>
        Returns:
        an immutable List view of this sequence
      • asJava

        @GwtIncompatible
        default Stream<T> asJava​(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
        Description copied from interface: Seq
        Creates an immutable List view of this Seq and passes it to the given action.

        The view is immutable: any attempt to modify it will throw UnsupportedOperationException at runtime.

        Specified by:
        asJava in interface LinearSeq<T>
        Specified by:
        asJava in interface Seq<T>
        Parameters:
        action - a side-effecting operation that receives an immutable java.util.List view
        Returns:
        this sequence
        See Also:
        Seq.asJava()
      • asJavaMutable

        @GwtIncompatible
        default java.util.List<T> asJavaMutable()
        Description copied from interface: Seq
        Returns a mutable List view of this Seq. All standard mutator methods of the List interface are supported and modify the underlying view.

        Unlike Seq.asJava(), this view allows modifications, but the performance characteristics correspond to the underlying persistent Vavr collection.

        Specified by:
        asJavaMutable in interface Seq<T>
        Returns:
        a mutable List view of this sequence
        See Also:
        Seq.asJava()
      • asJavaMutable

        @GwtIncompatible
        default Stream<T> asJavaMutable​(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
        Description copied from interface: Seq
        Creates a mutable List view of this Seq and passes it to the given action.

        The view supports all standard mutator methods. The result of the action determines what is returned:

        • If only read operations are performed, this instance is returned.
        • If any write operations are performed, a new Seq reflecting those changes is returned.
        Specified by:
        asJavaMutable in interface LinearSeq<T>
        Specified by:
        asJavaMutable in interface Seq<T>
        Parameters:
        action - a side-effecting operation that receives a mutable java.util.List view
        Returns:
        this sequence or a new sequence reflecting modifications made through the view
        See Also:
        Seq.asJavaMutable()
      • collect

        default <R> Stream<R> collect​(@NonNull PartialFunction<? super T,​? extends R> partialFunction)
        Description copied from interface: Traversable
        Applies a PartialFunction to all elements that are defined for it and collects the results.

        For each element in iteration order, the function is first tested:

        
         partialFunction.isDefinedAt(element)
         
        If true, the element is mapped to type R:
        
         R newElement = partialFunction.apply(element)
         

        Note: If this Traversable is ordered (i.e., extends Ordered), the caller must ensure that the resulting elements are comparable (i.e., implement Comparable).

        Specified by:
        collect in interface LinearSeq<T>
        Specified by:
        collect in interface Seq<T>
        Specified by:
        collect in interface Traversable<T>
        Type Parameters:
        R - the type of elements in the resulting Traversable
        Parameters:
        partialFunction - a function that may not be defined for all elements of this traversable
        Returns:
        a new Traversable containing the results of applying the partial function
      • combinations

        default Stream<Stream<T>> combinations()
        Description copied from interface: Seq
        Returns a sequence containing all combinations of elements from this sequence, for all sizes from 0 to length().

        Examples:

         
         [].combinations() = [[]]
        
         [1,2,3].combinations() = [
           [],                  // k = 0
           [1], [2], [3],       // k = 1
           [1,2], [1,3], [2,3], // k = 2
           [1,2,3]              // k = 3
         ]
         
         
        Specified by:
        combinations in interface LinearSeq<T>
        Specified by:
        combinations in interface Seq<T>
        Returns:
        a sequence of sequences representing all combinations of this sequence's elements
      • combinations

        default Stream<Stream<T>> combinations​(int k)
        Description copied from interface: Seq
        Returns all subsets of this sequence containing exactly k distinct elements, i.e., the k-combinations of this sequence.
        Specified by:
        combinations in interface LinearSeq<T>
        Specified by:
        combinations in interface Seq<T>
        Parameters:
        k - the size of each subset
        Returns:
        a sequence of sequences representing all k-element combinations
        See Also:
        Combination
      • crossProduct

        default Iterator<Stream<T>> crossProduct​(int power)
        Description copied from interface: Seq
        Returns the n-ary Cartesian power (cross product) of this sequence. Each element of the resulting iterator is a sequence of length power, containing all possible combinations of elements from this sequence.

        Example for power = 2:

        
         // Result: [(A,A), (A,B), (A,C), ..., (B,A), (B,B), ..., (Z,Y), (Z,Z)]
         CharSeq.rangeClosed('A', 'Z').crossProduct(2);
         

        If power is negative, the result is an empty iterator:

        
         // Result: ()
         CharSeq.rangeClosed('A', 'Z').crossProduct(-1);
         
        Specified by:
        crossProduct in interface LinearSeq<T>
        Specified by:
        crossProduct in interface Seq<T>
        Parameters:
        power - the number of Cartesian multiplications
        Returns:
        an Iterator over sequences representing the Cartesian power of this sequence
      • cycle

        default Stream<T> cycle()
        Repeat the elements of this Stream infinitely.

        Example:

         
         // = 1, 2, 3, 1, 2, 3, 1, 2, 3, ...
         Stream.of(1, 2, 3).cycle();
         
         
        Returns:
        A new Stream containing this elements cycled.
      • cycle

        default Stream<T> cycle​(int count)
        Repeat the elements of this Stream count times.

        Example:

         
         // = empty
         Stream.of(1, 2, 3).cycle(0);
        
         // = 1, 2, 3
         Stream.of(1, 2, 3).cycle(1);
        
         // = 1, 2, 3, 1, 2, 3, 1, 2, 3
         Stream.of(1, 2, 3).cycle(3);
         
         
        Parameters:
        count - the number of cycles to be performed
        Returns:
        A new Stream containing this elements cycled count times.
      • distinct

        default Stream<T> distinct()
        Description copied from interface: Traversable
        Returns a new Traversable containing the elements of this instance with all duplicates removed. Element equality is determined using equals.
        Specified by:
        distinct in interface LinearSeq<T>
        Specified by:
        distinct in interface Seq<T>
        Specified by:
        distinct in interface Traversable<T>
        Returns:
        a new Traversable without duplicate elements
      • distinctBy

        default Stream<T> distinctBy​(@NonNull java.util.Comparator<? super T> comparator)
        Description copied from interface: Traversable
        Returns a new Traversable containing the elements of this instance without duplicates, as determined by the given comparator.
        Specified by:
        distinctBy in interface LinearSeq<T>
        Specified by:
        distinctBy in interface Seq<T>
        Specified by:
        distinctBy in interface Traversable<T>
        Parameters:
        comparator - a comparator used to determine equality of elements
        Returns:
        a new Traversable with duplicates removed
      • distinctBy

        default <U> Stream<T> distinctBy​(@NonNull java.util.function.Function<? super T,​? extends U> keyExtractor)
        Description copied from interface: Traversable
        Returns a new Traversable containing the elements of this instance without duplicates, based on keys extracted from elements using keyExtractor.

        The first occurrence of each key is retained in the resulting sequence.

        Specified by:
        distinctBy in interface LinearSeq<T>
        Specified by:
        distinctBy in interface Seq<T>
        Specified by:
        distinctBy in interface Traversable<T>
        Type Parameters:
        U - the type of key
        Parameters:
        keyExtractor - a function to extract keys for determining uniqueness
        Returns:
        a new Traversable with duplicates removed based on keys
      • distinctByKeepLast

        default Stream<T> distinctByKeepLast​(@NonNull java.util.Comparator<? super T> comparator)
        Description copied from interface: Seq
        Returns a sequence with duplicate elements removed, as determined by the provided comparator. When duplicates are found, the **last occurrence** of each element is retained.
        Specified by:
        distinctByKeepLast in interface LinearSeq<T>
        Specified by:
        distinctByKeepLast in interface Seq<T>
        Parameters:
        comparator - a comparator defining equality between elements
        Returns:
        a new sequence with duplicates removed, keeping the last occurrence of each element
      • distinctByKeepLast

        default <U> Stream<T> distinctByKeepLast​(@NonNull java.util.function.Function<? super T,​? extends U> keyExtractor)
        Description copied from interface: Seq
        Returns a sequence with duplicates removed based on a key extracted from each element. The key is obtained via the provided keyExtractor function. When duplicates are found, the **last occurrence** of each element for a given key is retained.
        Specified by:
        distinctByKeepLast in interface LinearSeq<T>
        Specified by:
        distinctByKeepLast in interface Seq<T>
        Type Parameters:
        U - the type of the key used for determining uniqueness
        Parameters:
        keyExtractor - a function extracting a key from each element for uniqueness comparison
        Returns:
        a new sequence of elements distinct by the extracted key, keeping the last occurrence
      • drop

        default Stream<T> drop​(int n)
        Description copied from interface: Traversable
        Returns a new Traversable without the first n elements, or an empty instance if this contains fewer than n elements.
        Specified by:
        drop in interface LinearSeq<T>
        Specified by:
        drop in interface Seq<T>
        Specified by:
        drop in interface Traversable<T>
        Parameters:
        n - the number of elements to drop
        Returns:
        a new instance excluding the first n elements
      • dropUntil

        default Stream<T> dropUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new Traversable starting from the first element that satisfies the given predicate, dropping all preceding elements.
        Specified by:
        dropUntil in interface LinearSeq<T>
        Specified by:
        dropUntil in interface Seq<T>
        Specified by:
        dropUntil in interface Traversable<T>
        Parameters:
        predicate - a condition tested on each element
        Returns:
        a new instance starting from the first element matching the predicate
      • dropWhile

        default Stream<T> dropWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new Traversable starting from the first element that does not satisfy the given predicate, dropping all preceding elements.

        This is equivalent to dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.

        Specified by:
        dropWhile in interface LinearSeq<T>
        Specified by:
        dropWhile in interface Seq<T>
        Specified by:
        dropWhile in interface Traversable<T>
        Parameters:
        predicate - a condition tested on each element
        Returns:
        a new instance starting from the first element not matching the predicate
      • dropRight

        default Stream<T> dropRight​(int n)
        Description copied from interface: Traversable
        Returns a new Traversable without the last n elements, or an empty instance if this contains fewer than n elements.
        Specified by:
        dropRight in interface LinearSeq<T>
        Specified by:
        dropRight in interface Seq<T>
        Specified by:
        dropRight in interface Traversable<T>
        Parameters:
        n - the number of elements to drop from the end
        Returns:
        a new instance excluding the last n elements
      • dropRightUntil

        default Stream<T> dropRightUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Drops elements from the end of the sequence until an element satisfies the given predicate. The returned sequence includes the last element that satisfies the predicate.
        Specified by:
        dropRightUntil in interface LinearSeq<T>
        Specified by:
        dropRightUntil in interface Seq<T>
        Parameters:
        predicate - a condition to test elements, starting from the end
        Returns:
        a new sequence containing all elements up to and including the last element that satisfies the predicate
      • dropRightWhile

        default Stream<T> dropRightWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Drops elements from the end of the sequence while the given predicate holds.

        This is equivalent to dropRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.

        Specified by:
        dropRightWhile in interface LinearSeq<T>
        Specified by:
        dropRightWhile in interface Seq<T>
        Parameters:
        predicate - a condition to test elements, starting from the end
        Returns:
        a new sequence containing all elements up to and including the last element that does not satisfy the predicate
      • filter

        default Stream<T> filter​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new traversable containing only the elements that satisfy the given predicate.
        Specified by:
        filter in interface LinearSeq<T>
        Specified by:
        filter in interface Seq<T>
        Specified by:
        filter in interface Traversable<T>
        Parameters:
        predicate - the condition to test elements
        Returns:
        a traversable with elements matching the predicate
      • reject

        default Stream<T> reject​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Returns a new traversable containing only the elements that do not satisfy the given predicate.

        This is equivalent to filter(predicate.negate()).

        Specified by:
        reject in interface LinearSeq<T>
        Specified by:
        reject in interface Seq<T>
        Specified by:
        reject in interface Traversable<T>
        Parameters:
        predicate - the condition to test elements
        Returns:
        a traversable with elements not matching the predicate
      • flatMap

        default <U> Stream<U> flatMap​(@NonNull java.util.function.Function<? super T,​? extends java.lang.Iterable<? extends U>> mapper)
        Description copied from interface: Traversable
        Transforms each element of this Traversable into an Iterable of elements and flattens the resulting iterables into a single Traversable.
        Specified by:
        flatMap in interface LinearSeq<T>
        Specified by:
        flatMap in interface Seq<T>
        Specified by:
        flatMap in interface Traversable<T>
        Type Parameters:
        U - the type of elements in the resulting Traversable
        Parameters:
        mapper - a function mapping elements to iterables
        Returns:
        a new Traversable containing all elements produced by applying mapper and flattening
      • get

        default T get​(int index)
        Description copied from interface: Seq
        Returns the element at the specified index.
        Specified by:
        get in interface Seq<T>
        Parameters:
        index - the position of the element to retrieve
        Returns:
        the element at the given index
      • groupBy

        default <C> Map<C,​Stream<T>> groupBy​(@NonNull java.util.function.Function<? super T,​? extends C> classifier)
        Description copied from interface: Traversable
        Groups elements of this Traversable based on a classifier function.
        Specified by:
        groupBy in interface LinearSeq<T>
        Specified by:
        groupBy in interface Seq<T>
        Specified by:
        groupBy in interface Traversable<T>
        Type Parameters:
        C - The type of the group keys
        Parameters:
        classifier - A function that assigns each element to a group
        Returns:
        A map where each key corresponds to a group of elements
        See Also:
        Traversable.arrangeBy(Function)
      • grouped

        default Iterator<Stream<T>> grouped​(int size)
        Description copied from interface: Traversable
        Splits this Traversable into consecutive blocks of the given size.

        Let length be the number of elements in this Traversable:

        • If empty, the resulting Iterator is empty.
        • If size <= length, the resulting Iterator contains length / size blocks of size size and possibly a final smaller block of size length % size.
        • If size > length, the resulting Iterator contains a single block of size length.

        Examples:

         
         [].grouped(1) = []
         [].grouped(0) throws
         [].grouped(-1) throws
         [1,2,3,4].grouped(2) = [[1,2],[3,4]]
         [1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
         [1,2,3,4].grouped(5) = [[1,2,3,4]]
         
         

        Note: grouped(size) is equivalent to sliding(size, size).

        Specified by:
        grouped in interface LinearSeq<T>
        Specified by:
        grouped in interface Seq<T>
        Specified by:
        grouped in interface Traversable<T>
        Parameters:
        size - the block size; must be positive
        Returns:
        an Iterator over blocks of elements
      • hasDefiniteSize

        default boolean hasDefiniteSize()
        Description copied from interface: Traversable
        Indicates whether this Traversable has a known finite size.

        This should typically be implemented by concrete classes, not interfaces.

        Specified by:
        hasDefiniteSize in interface Traversable<T>
        Returns:
        true if the number of elements is finite and known, false otherwise.
      • indexOf

        default int indexOf​(T element,
                            int from)
        Description copied from interface: Seq
        Returns the index of the first occurrence of the given element, starting at the specified index, or -1 if this sequence does not contain the element.
        Specified by:
        indexOf in interface Seq<T>
        Parameters:
        element - the element to search for
        from - the starting index for the search
        Returns:
        the index of the first occurrence at or after from, or -1 if not found
      • init

        default Stream<T> init()
        Description copied from interface: Traversable
        Returns all elements of this Traversable except the last one.

        This is the dual of Traversable.tail().

        Specified by:
        init in interface LinearSeq<T>
        Specified by:
        init in interface Seq<T>
        Specified by:
        init in interface Traversable<T>
        Returns:
        a new instance containing all elements except the last
      • insert

        default Stream<T> insert​(int index,
                                 T element)
        Description copied from interface: Seq
        Returns a new sequence with the given element inserted at the specified index.
        Specified by:
        insert in interface LinearSeq<T>
        Specified by:
        insert in interface Seq<T>
        Parameters:
        index - the position at which to insert the element
        element - the element to insert
        Returns:
        a new Seq with the element inserted
      • insertAll

        default Stream<T> insertAll​(int index,
                                    @NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Seq
        Returns a new sequence with the given elements inserted at the specified index.
        Specified by:
        insertAll in interface LinearSeq<T>
        Specified by:
        insertAll in interface Seq<T>
        Parameters:
        index - the position at which to insert the elements
        elements - the elements to insert; must not be null
        Returns:
        a new Seq with the elements inserted
      • intersperse

        default Stream<T> intersperse​(T element)
        Description copied from interface: Seq
        Returns a new sequence where the given element is inserted between all elements of this sequence.
        Specified by:
        intersperse in interface LinearSeq<T>
        Specified by:
        intersperse in interface Seq<T>
        Parameters:
        element - the element to intersperse
        Returns:
        a new Seq with the element interspersed
      • isAsync

        default boolean isAsync()
        A Stream is computed synchronously.
        Specified by:
        isAsync in interface Value<T>
        Returns:
        false
      • isLazy

        default boolean isLazy()
        A Stream is computed lazily.
        Specified by:
        isLazy in interface Value<T>
        Returns:
        true
      • isTraversableAgain

        default boolean isTraversableAgain()
        Description copied from interface: Traversable
        Checks if this Traversable can be traversed multiple times without side effects.

        Implementations should provide the correct behavior; this is not meant for interfaces alone.

        Specified by:
        isTraversableAgain in interface Traversable<T>
        Returns:
        true if this Traversable is guaranteed to be repeatably traversable, false otherwise
      • last

        default T last()
        Description copied from interface: Traversable
        Returns the last element of this Traversable.
        Specified by:
        last in interface Traversable<T>
        Returns:
        the last element
      • lastIndexOf

        default int lastIndexOf​(T element,
                                int end)
        Description copied from interface: Seq
        Returns the index of the last occurrence of the given element at or before the specified end index, or -1 if this sequence does not contain the element.
        Specified by:
        lastIndexOf in interface Seq<T>
        Parameters:
        element - the element to search for
        end - the maximum index to consider
        Returns:
        the index of the last occurrence at or before end, or -1 if not found
      • length

        default int length()
        Description copied from interface: Traversable
        Returns the number of elements in this Traversable.

        Equivalent to Traversable.size().

        Specified by:
        length in interface Traversable<T>
        Returns:
        the number of elements
      • map

        default <U> Stream<U> map​(@NonNull java.util.function.Function<? super T,​? extends U> mapper)
        Description copied from interface: Traversable
        Transforms the elements of this Traversable to a new type, preserving order if defined.
        Specified by:
        map in interface LinearSeq<T>
        Specified by:
        map in interface Seq<T>
        Specified by:
        map in interface Traversable<T>
        Specified by:
        map in interface Value<T>
        Type Parameters:
        U - the target element type
        Parameters:
        mapper - a mapping function
        Returns:
        a new Traversable containing the mapped elements
      • mapTo

        default <U> Stream<U> mapTo​(U value)
        Description copied from interface: Value
        Maps the underlying value to another fixed value.
        Specified by:
        mapTo in interface LinearSeq<T>
        Specified by:
        mapTo in interface Seq<T>
        Specified by:
        mapTo in interface Traversable<T>
        Specified by:
        mapTo in interface Value<T>
        Type Parameters:
        U - The new component type
        Parameters:
        value - value to replace the contents with
        Returns:
        A new value
      • padTo

        default Stream<T> padTo​(int length,
                                T element)
        Description copied from interface: Seq
        Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.

        Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.

        Specified by:
        padTo in interface LinearSeq<T>
        Specified by:
        padTo in interface Seq<T>
        Parameters:
        length - the target length of the resulting sequence
        element - the element to append as padding
        Returns:
        a new Seq consisting of this sequence followed by the minimal number of occurrences of element to reach at least length
      • leftPadTo

        default Stream<T> leftPadTo​(int length,
                                    T element)
        Description copied from interface: Seq
        Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.

        Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.

        Specified by:
        leftPadTo in interface Seq<T>
        Parameters:
        length - the target length of the resulting sequence
        element - the element to prepend as padding
        Returns:
        a new Seq consisting of this sequence prepended by the minimal number of occurrences of element to reach at least length
      • orElse

        default Stream<T> orElse​(@NonNull java.lang.Iterable<? extends T> other)
        Description copied from interface: Traversable
        Returns this Traversable if it is non-empty; otherwise, returns the given alternative.
        Specified by:
        orElse in interface LinearSeq<T>
        Specified by:
        orElse in interface Seq<T>
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        other - an alternative Traversable to return if this is empty
        Returns:
        this Traversable if non-empty, otherwise other
      • orElse

        default Stream<T> orElse​(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
        Description copied from interface: Traversable
        Returns this Traversable if it is non-empty; otherwise, returns the result of evaluating the given supplier.
        Specified by:
        orElse in interface LinearSeq<T>
        Specified by:
        orElse in interface Seq<T>
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        supplier - a supplier of an alternative Traversable if this is empty
        Returns:
        this Traversable if non-empty, otherwise the result of supplier.get()
      • patch

        default Stream<T> patch​(int from,
                                @NonNull java.lang.Iterable<? extends T> that,
                                int replaced)
        Description copied from interface: Seq
        Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.
        Specified by:
        patch in interface LinearSeq<T>
        Specified by:
        patch in interface Seq<T>
        Parameters:
        from - the starting index of the slice to be replaced
        that - the sequence of elements to insert; must not be null
        replaced - the number of elements to remove from this sequence starting at from
        Returns:
        a new Seq with the specified slice replaced
      • partition

        default Tuple2<Stream<T>,​Stream<T>> partition​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Splits this Traversable into two partitions according to a predicate.

        The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.

        Specified by:
        partition in interface LinearSeq<T>
        Specified by:
        partition in interface Seq<T>
        Specified by:
        partition in interface Traversable<T>
        Parameters:
        predicate - a predicate used to classify elements
        Returns:
        a Tuple2 containing the two resulting Traversable instances
      • peek

        default Stream<T> peek​(@NonNull java.util.function.Consumer<? super T> action)
        Description copied from interface: Value
        Performs the given action on the first element if this is an eager implementation. Performs the given action on all elements (the first immediately, successive deferred), if this is a lazy implementation.
        Specified by:
        peek in interface LinearSeq<T>
        Specified by:
        peek in interface Seq<T>
        Specified by:
        peek in interface Traversable<T>
        Specified by:
        peek in interface Value<T>
        Parameters:
        action - The action that will be performed on the element(s).
        Returns:
        this instance
      • permutations

        default Stream<Stream<T>> permutations()
        Description copied from interface: Seq
        Returns all unique permutations of this sequence.

        Example:

        
         [].permutations() = []
        
         [1, 2, 3].permutations() = [
           [1, 2, 3],
           [1, 3, 2],
           [2, 1, 3],
           [2, 3, 1],
           [3, 1, 2],
           [3, 2, 1]
         ]
         
        Specified by:
        permutations in interface LinearSeq<T>
        Specified by:
        permutations in interface Seq<T>
        Returns:
        a sequence of all unique permutations of this sequence
      • prepend

        default Stream<T> prepend​(T element)
        Description copied from interface: Seq
        Returns a new sequence with the given element prepended to this sequence.
        Specified by:
        prepend in interface LinearSeq<T>
        Specified by:
        prepend in interface Seq<T>
        Parameters:
        element - the element to prepend
        Returns:
        a new Seq with the element added at the front
      • prependAll

        default Stream<T> prependAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Seq
        Returns a new sequence with all given elements prepended to this sequence.
        Specified by:
        prependAll in interface LinearSeq<T>
        Specified by:
        prependAll in interface Seq<T>
        Parameters:
        elements - the elements to prepend; must not be null
        Returns:
        a new Seq with the elements added at the front
      • remove

        default Stream<T> remove​(T element)
        Description copied from interface: Seq
        Returns a new sequence with the first occurrence of the given element removed.
        Specified by:
        remove in interface LinearSeq<T>
        Specified by:
        remove in interface Seq<T>
        Parameters:
        element - the element to remove
        Returns:
        a new Seq without the first occurrence of the element
      • removeFirst

        default Stream<T> removeFirst​(@NonNull java.util.function.Predicate<T> predicate)
        Description copied from interface: Seq
        Returns a new sequence with the first element that satisfies the given predicate removed.
        Specified by:
        removeFirst in interface LinearSeq<T>
        Specified by:
        removeFirst in interface Seq<T>
        Parameters:
        predicate - the predicate used to identify the element to remove; must not be null
        Returns:
        a new Seq without the first matching element
      • removeLast

        default Stream<T> removeLast​(@NonNull java.util.function.Predicate<T> predicate)
        Description copied from interface: Seq
        Returns a new sequence with the last element that satisfies the given predicate removed.
        Specified by:
        removeLast in interface LinearSeq<T>
        Specified by:
        removeLast in interface Seq<T>
        Parameters:
        predicate - the predicate used to identify the element to remove; must not be null
        Returns:
        a new Seq without the last matching element
      • removeAt

        default Stream<T> removeAt​(int index)
        Description copied from interface: Seq
        Returns a new sequence with the element at the specified position removed. Subsequent elements are shifted to the left (indices decreased by one).
        Specified by:
        removeAt in interface LinearSeq<T>
        Specified by:
        removeAt in interface Seq<T>
        Parameters:
        index - the position of the element to remove
        Returns:
        a new Seq without the element at the specified index
      • removeAll

        default Stream<T> removeAll​(T element)
        Description copied from interface: Seq
        Returns a new sequence with all occurrences of the given element removed.
        Specified by:
        removeAll in interface LinearSeq<T>
        Specified by:
        removeAll in interface Seq<T>
        Parameters:
        element - the element to remove
        Returns:
        a new Seq without any occurrences of the element
      • removeAll

        default Stream<T> removeAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Seq
        Returns a new sequence with all occurrences of the given elements removed.
        Specified by:
        removeAll in interface LinearSeq<T>
        Specified by:
        removeAll in interface Seq<T>
        Parameters:
        elements - the elements to remove; must not be null
        Returns:
        a new Seq without any of the given elements
      • removeAll

        @Deprecated
        default Stream<T> removeAll​(@NonNull java.util.function.Predicate<? super T> predicate)
        Deprecated.
        Description copied from interface: Seq
        Returns a new Seq consisting of all elements which do not satisfy the given predicate.
        Specified by:
        removeAll in interface LinearSeq<T>
        Specified by:
        removeAll in interface Seq<T>
        Parameters:
        predicate - the predicate used to test elements
        Returns:
        a new Seq
      • replace

        default Stream<T> replace​(T currentElement,
                                  T newElement)
        Description copied from interface: Traversable
        Replaces the first occurrence of currentElement with newElement, if it exists.
        Specified by:
        replace in interface LinearSeq<T>
        Specified by:
        replace in interface Seq<T>
        Specified by:
        replace in interface Traversable<T>
        Parameters:
        currentElement - the element to be replaced
        newElement - the replacement element
        Returns:
        a new Traversable with the first occurrence of currentElement replaced by newElement
      • replaceAll

        default Stream<T> replaceAll​(T currentElement,
                                     T newElement)
        Description copied from interface: Traversable
        Replaces all occurrences of currentElement with newElement.
        Specified by:
        replaceAll in interface LinearSeq<T>
        Specified by:
        replaceAll in interface Seq<T>
        Specified by:
        replaceAll in interface Traversable<T>
        Parameters:
        currentElement - the element to be replaced
        newElement - the replacement element
        Returns:
        a new Traversable with all occurrences of currentElement replaced by newElement
      • retainAll

        default Stream<T> retainAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Traversable
        Retains only the elements from this Traversable that are contained in the given elements.
        Specified by:
        retainAll in interface LinearSeq<T>
        Specified by:
        retainAll in interface Seq<T>
        Specified by:
        retainAll in interface Traversable<T>
        Parameters:
        elements - the elements to keep
        Returns:
        a new Traversable containing only the elements present in elements, in their original order
      • reverse

        default Stream<T> reverse()
        Description copied from interface: Seq
        Returns a new sequence with the order of elements reversed.
        Specified by:
        reverse in interface LinearSeq<T>
        Specified by:
        reverse in interface Seq<T>
        Returns:
        a new Seq with elements in reversed order
      • rotateLeft

        default Stream<T> rotateLeft​(int n)
        Description copied from interface: Seq
        Returns a new sequence with the elements circularly rotated to the left by the specified distance.

        Example:

        
         // Result: List(3, 4, 5, 1, 2)
         List.of(1, 2, 3, 4, 5).rotateLeft(2);
         
        Specified by:
        rotateLeft in interface LinearSeq<T>
        Specified by:
        rotateLeft in interface Seq<T>
        Parameters:
        n - the number of positions to rotate left
        Returns:
        a new Seq with elements rotated left
      • rotateRight

        default Stream<T> rotateRight​(int n)
        Description copied from interface: Seq
        Returns a new sequence with the elements circularly rotated to the right by the specified distance.

        Example:

        
         // Result: List(4, 5, 1, 2, 3)
         List.of(1, 2, 3, 4, 5).rotateRight(2);
         
        Specified by:
        rotateRight in interface LinearSeq<T>
        Specified by:
        rotateRight in interface Seq<T>
        Parameters:
        n - the number of positions to rotate right
        Returns:
        a new Seq with elements rotated right
      • scan

        default Stream<T> scan​(T zero,
                               @NonNull java.util.function.BiFunction<? super T,​? super T,​? extends T> operation)
        Description copied from interface: Traversable
        Computes a prefix scan of the elements of this Traversable.

        The neutral element zero may be applied more than once.

        Specified by:
        scan in interface LinearSeq<T>
        Specified by:
        scan in interface Seq<T>
        Specified by:
        scan in interface Traversable<T>
        Parameters:
        zero - the neutral element for the operator
        operation - an associative binary operator
        Returns:
        a new Traversable containing the prefix scan of the elements
      • scanLeft

        default <U> Stream<U> scanLeft​(U zero,
                                       @NonNull java.util.function.BiFunction<? super U,​? super T,​? extends U> operation)
        Description copied from interface: Traversable
        Produces a collection containing cumulative results of applying the operator from left to right.

        Will not terminate for infinite collections. The results may vary across runs unless the collection is ordered.

        Specified by:
        scanLeft in interface LinearSeq<T>
        Specified by:
        scanLeft in interface Seq<T>
        Specified by:
        scanLeft in interface Traversable<T>
        Type Parameters:
        U - the type of the resulting elements
        Parameters:
        zero - the initial value
        operation - a binary operator applied to the intermediate result and each element
        Returns:
        a new Traversable containing the cumulative results
      • scanRight

        default <U> Stream<U> scanRight​(U zero,
                                        @NonNull java.util.function.BiFunction<? super T,​? super U,​? extends U> operation)
        Description copied from interface: Traversable
        Produces a collection containing cumulative results of applying the operator from right to left.

        The head of the resulting collection is the last cumulative result. Will not terminate for infinite collections. Results may vary across runs unless the collection is ordered.

        Specified by:
        scanRight in interface LinearSeq<T>
        Specified by:
        scanRight in interface Seq<T>
        Specified by:
        scanRight in interface Traversable<T>
        Type Parameters:
        U - the type of the resulting elements
        Parameters:
        zero - the initial value
        operation - a binary operator applied to each element and the intermediate result
        Returns:
        a new Traversable containing the cumulative results
      • shuffle

        default Stream<T> shuffle()
        Description copied from interface: Seq
        Returns a new sequence with the elements randomly shuffled.
        Specified by:
        shuffle in interface LinearSeq<T>
        Specified by:
        shuffle in interface Seq<T>
        Returns:
        a new Seq containing the same elements in a random order
      • slice

        default Stream<T> slice​(int beginIndex,
                                int endIndex)
        Description copied from interface: Seq
        Returns a subsequence (slice) of this sequence, starting at beginIndex (inclusive) and ending at endIndex (exclusive).

        Examples:

        
         List.of(1, 2, 3, 4).slice(1, 3); // = (2, 3)
         List.of(1, 2, 3, 4).slice(0, 4); // = (1, 2, 3, 4)
         List.of(1, 2, 3, 4).slice(2, 2); // = ()
         List.of(1, 2).slice(1, 0);       // = ()
         List.of(1, 2).slice(-10, 10);    // = (1, 2)
         

        See also Seq.subSequence(int, int), which may throw an exception instead of returning a sequence in some cases.

        Specified by:
        slice in interface LinearSeq<T>
        Specified by:
        slice in interface Seq<T>
        Parameters:
        beginIndex - the starting index (inclusive)
        endIndex - the ending index (exclusive)
        Returns:
        a new Seq representing the specified slice
      • slideBy

        default Iterator<Stream<T>> slideBy​(@NonNull java.util.function.Function<? super T,​?> classifier)
        Description copied from interface: Traversable
        Partitions this Traversable into consecutive non-overlapping windows according to a classification function.

        Each window contains elements with the same class, as determined by classifier. Two consecutive elements belong to the same window only if classifier returns equal values for both. Otherwise, the current window ends and a new window begins with the next element.

        Examples:

        
         [].slideBy(Function.identity()) = []
         [1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]]
         [1,2,3,10,12,5,7,20,29].slideBy(x -> x / 10) = [[1,2,3],[10,12],[5,7],[20,29]]
         
        Specified by:
        slideBy in interface LinearSeq<T>
        Specified by:
        slideBy in interface Seq<T>
        Specified by:
        slideBy in interface Traversable<T>
        Parameters:
        classifier - A function classifying elements into groups
        Returns:
        An Iterator of windows (grouped elements)
      • sliding

        default Iterator<Stream<T>> sliding​(int size)
        Description copied from interface: Traversable
        Slides a window of a given size over this Traversable with a step size of 1.

        This is equivalent to calling Traversable.sliding(int, int) with a step size of 1.

        Specified by:
        sliding in interface LinearSeq<T>
        Specified by:
        sliding in interface Seq<T>
        Specified by:
        sliding in interface Traversable<T>
        Parameters:
        size - a positive window size
        Returns:
        An Iterator of windows, each containing up to size elements
      • sliding

        default Iterator<Stream<T>> sliding​(int size,
                                            int step)
        Description copied from interface: Traversable
        Slides a window of a specific size with a given step over this Traversable.

        Examples:

        
         [].sliding(1, 1) = []
         [1,2,3,4,5].sliding(2, 3) = [[1,2],[4,5]]
         [1,2,3,4,5].sliding(2, 4) = [[1,2],[5]]
         [1,2,3,4,5].sliding(2, 5) = [[1,2]]
         [1,2,3,4].sliding(5, 3) = [[1,2,3,4],[4]]
         
        Specified by:
        sliding in interface LinearSeq<T>
        Specified by:
        sliding in interface Seq<T>
        Specified by:
        sliding in interface Traversable<T>
        Parameters:
        size - a positive window size
        step - a positive step size
        Returns:
        an Iterator of windows with the given size and step
      • sorted

        default Stream<T> sorted()
        Description copied from interface: Seq
        Returns a new sequence with elements sorted according to their natural order.
        Specified by:
        sorted in interface LinearSeq<T>
        Specified by:
        sorted in interface Seq<T>
        Returns:
        a new Seq with elements in natural order
      • sorted

        default Stream<T> sorted​(@NonNull java.util.Comparator<? super T> comparator)
        Description copied from interface: Seq
        Returns a new sequence with elements sorted according to the given Comparator.
        Specified by:
        sorted in interface LinearSeq<T>
        Specified by:
        sorted in interface Seq<T>
        Parameters:
        comparator - the comparator used to order elements; must not be null
        Returns:
        a new Seq with elements sorted according to the comparator
      • sortBy

        default <U extends java.lang.Comparable<? super U>> Stream<T> sortBy​(@NonNull java.util.function.Function<? super T,​? extends U> mapper)
        Description copied from interface: Seq
        Returns a new sequence sorted by comparing elements in a different domain defined by the given mapper.
        Specified by:
        sortBy in interface LinearSeq<T>
        Specified by:
        sortBy in interface Seq<T>
        Type Parameters:
        U - the type used for comparison
        Parameters:
        mapper - a function mapping elements to a Comparable domain; must not be null
        Returns:
        a new Seq sorted according to the mapped values
      • sortBy

        default <U> Stream<T> sortBy​(@NonNull java.util.Comparator<? super U> comparator,
                                     java.util.function.Function<? super T,​? extends U> mapper)
        Description copied from interface: Seq
        Returns a new sequence sorted by comparing elements in a different domain defined by the given mapper, using the provided comparator.
        Specified by:
        sortBy in interface LinearSeq<T>
        Specified by:
        sortBy in interface Seq<T>
        Type Parameters:
        U - the type used for comparison
        Parameters:
        comparator - the comparator used to compare mapped values; must not be null
        mapper - a function mapping elements to the domain for comparison; must not be null
        Returns:
        a new Seq sorted according to the mapped values and comparator
      • span

        default Tuple2<Stream<T>,​Stream<T>> span​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Splits this Traversable into a prefix and remainder according to the given predicate.

        The first element of the returned Tuple is the longest prefix of elements satisfying predicate, and the second element is the remaining elements.

        Specified by:
        span in interface LinearSeq<T>
        Specified by:
        span in interface Seq<T>
        Specified by:
        span in interface Traversable<T>
        Parameters:
        predicate - a predicate used to determine the prefix
        Returns:
        a Tuple containing the prefix and remainder
      • splitAt

        default Tuple2<Stream<T>,​Stream<T>> splitAt​(int n)
        Description copied from interface: Seq
        Splits this sequence at the specified index.

        The result of splitAt(n) is equivalent to Tuple.of(take(n), drop(n)).

        Specified by:
        splitAt in interface Seq<T>
        Parameters:
        n - the index at which to split
        Returns:
        a Tuple2 containing the first n elements and the remaining elements
      • splitAt

        default Tuple2<Stream<T>,​Stream<T>> splitAt​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Splits this sequence at the first element satisfying the given predicate.
        Specified by:
        splitAt in interface Seq<T>
        Parameters:
        predicate - the predicate used to determine the split point; must not be null
        Returns:
        a Tuple2 containing the sequence before the first matching element and the remaining sequence
      • splitAtInclusive

        default Tuple2<Stream<T>,​Stream<T>> splitAtInclusive​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Splits this sequence at the first element satisfying the given predicate, including the element in the first part.
        Specified by:
        splitAtInclusive in interface Seq<T>
        Parameters:
        predicate - the predicate used to determine the split point; must not be null
        Returns:
        a Tuple2 containing the sequence up to and including the first matching element and the remaining sequence
      • stringPrefix

        default java.lang.String stringPrefix()
        Description copied from interface: Value
        Returns the name of this Value type, which is used by toString().
        Specified by:
        stringPrefix in interface Value<T>
        Returns:
        This type name.
      • subSequence

        default Stream<T> subSequence​(int beginIndex)
        Description copied from interface: Seq
        Returns a Seq that is a subsequence of this sequence, starting from the specified beginIndex and extending to the end of this sequence.

        Examples:

        
         List.of(1, 2).subSequence(0);   // = (1, 2)
         List.of(1, 2).subSequence(1);   // = (2)
         List.of(1, 2).subSequence(2);   // = ()
         List.of(1, 2).subSequence(10);  // throws IndexOutOfBoundsException
         List.of(1, 2).subSequence(-10); // throws IndexOutOfBoundsException
         

        See also Seq.drop(int), which provides similar functionality but does not throw an exception for out-of-bounds indices.

        Specified by:
        subSequence in interface LinearSeq<T>
        Specified by:
        subSequence in interface Seq<T>
        Parameters:
        beginIndex - the starting index (inclusive) of the subsequence
        Returns:
        a new Seq representing the subsequence from beginIndex to the end
      • subSequence

        default Stream<T> subSequence​(int beginIndex,
                                      int endIndex)
        Description copied from interface: Seq
        Returns a Seq that is a subsequence of this sequence, starting from the specified beginIndex (inclusive) and ending at endIndex (exclusive).

        Examples:

        
         List.of(1, 2, 3, 4).subSequence(1, 3); // = (2, 3)
         List.of(1, 2, 3, 4).subSequence(0, 4); // = (1, 2, 3, 4)
         List.of(1, 2, 3, 4).subSequence(2, 2); // = ()
         List.of(1, 2).subSequence(1, 0);       // throws IndexOutOfBoundsException
         List.of(1, 2).subSequence(-10, 1);     // throws IndexOutOfBoundsException
         List.of(1, 2).subSequence(0, 10);      // throws IndexOutOfBoundsException
         

        See also Seq.slice(int, int), which returns an empty sequence instead of throwing exceptions when indices are out of range.

        Specified by:
        subSequence in interface LinearSeq<T>
        Specified by:
        subSequence in interface Seq<T>
        Parameters:
        beginIndex - the starting index (inclusive) of the subsequence
        endIndex - the ending index (exclusive) of the subsequence
        Returns:
        a new Seq representing the subsequence from beginIndex to endIndex - 1
      • tail

        Stream<T> tail()
        Description copied from interface: Traversable
        Returns a new Traversable without its first element.
        Specified by:
        tail in interface LinearSeq<T>
        Specified by:
        tail in interface Seq<T>
        Specified by:
        tail in interface Traversable<T>
        Returns:
        a new Traversable containing all elements except the first
      • take

        default Stream<T> take​(int n)
        Description copied from interface: Traversable
        Returns the first n elements of this Traversable, or all elements if n exceeds the length.

        Equivalent to sublist(0, max(0, min(length(), n))), but safe for n < 0 or n > length().

        If n < 0, an empty instance is returned. If n > length(), the full instance is returned.

        Specified by:
        take in interface LinearSeq<T>
        Specified by:
        take in interface Seq<T>
        Specified by:
        take in interface Traversable<T>
        Parameters:
        n - the number of elements to take
        Returns:
        a new Traversable containing the first n elements
      • takeUntil

        default Stream<T> takeUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Takes elements from this Traversable until the given predicate holds for an element.

        Equivalent to takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.

        Specified by:
        takeUntil in interface LinearSeq<T>
        Specified by:
        takeUntil in interface Seq<T>
        Specified by:
        takeUntil in interface Traversable<T>
        Parameters:
        predicate - a condition tested sequentially on the elements
        Returns:
        a new Traversable containing all elements before the first one that satisfies the predicate
      • takeWhile

        default Stream<T> takeWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Traversable
        Takes elements from this Traversable while the given predicate holds.
        Specified by:
        takeWhile in interface LinearSeq<T>
        Specified by:
        takeWhile in interface Seq<T>
        Specified by:
        takeWhile in interface Traversable<T>
        Parameters:
        predicate - a condition tested sequentially on the elements
        Returns:
        a new Traversable containing all elements up to (but not including) the first one that does not satisfy the predicate
      • takeRight

        default Stream<T> takeRight​(int n)
        Description copied from interface: Traversable
        Returns the last n elements of this Traversable, or all elements if n exceeds the length.

        Equivalent to sublist(max(0, length() - n), length()), but safe for n < 0 or n > length().

        If n < 0, an empty instance is returned. If n > length(), the full instance is returned.

        Specified by:
        takeRight in interface LinearSeq<T>
        Specified by:
        takeRight in interface Seq<T>
        Specified by:
        takeRight in interface Traversable<T>
        Parameters:
        n - the number of elements to take from the end
        Returns:
        a new Traversable containing the last n elements
      • takeRightUntil

        default Stream<T> takeRightUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Takes elements from the end of the sequence until an element satisfies the given predicate. The returned sequence starts after the last element that satisfies the predicate.
        Specified by:
        takeRightUntil in interface LinearSeq<T>
        Specified by:
        takeRightUntil in interface Seq<T>
        Parameters:
        predicate - a condition to test elements, starting from the end
        Returns:
        a new sequence containing all elements after the last element that satisfies the predicate
      • takeRightWhile

        default Stream<T> takeRightWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
        Description copied from interface: Seq
        Takes elements from the end of the sequence while the given predicate holds.

        This is an equivalent to takeRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.

        Specified by:
        takeRightWhile in interface LinearSeq<T>
        Specified by:
        takeRightWhile in interface Seq<T>
        Parameters:
        predicate - a condition to test elements, starting from the end
        Returns:
        a new sequence containing all elements after the last element that does not satisfy the predicate
      • transform

        default <U> U transform​(@NonNull java.util.function.Function<? super Stream<T>,​? extends U> f)
        Transforms this Stream.
        Type Parameters:
        U - Type of transformation result
        Parameters:
        f - A transformation
        Returns:
        An instance of type U
        Throws:
        java.lang.NullPointerException - if f is null
      • unzip

        default <T1,​T2> Tuple2<Stream<T1>,​Stream<T2>> unzip​(@NonNull java.util.function.Function<? super T,​Tuple2<? extends T1,​? extends T2>> unzipper)
        Description copied from interface: Traversable
        Unzips the elements of this Traversable by mapping each element to a pair and splitting them into two separate Traversable collections.
        Specified by:
        unzip in interface LinearSeq<T>
        Specified by:
        unzip in interface Seq<T>
        Specified by:
        unzip in interface Traversable<T>
        Type Parameters:
        T1 - type of the first element in the resulting pairs
        T2 - type of the second element in the resulting pairs
        Parameters:
        unzipper - a function that maps elements of this Traversable to pairs
        Returns:
        a Tuple2 containing two Traversable collections with the split elements
      • unzip3

        default <T1,​T2,​T3> Tuple3<Stream<T1>,​Stream<T2>,​Stream<T3>> unzip3​(@NonNull java.util.function.Function<? super T,​Tuple3<? extends T1,​? extends T2,​? extends T3>> unzipper)
        Description copied from interface: Traversable
        Unzips the elements of this Traversable by mapping each element to a triple and splitting them into three separate Traversable collections.
        Specified by:
        unzip3 in interface Seq<T>
        Specified by:
        unzip3 in interface Traversable<T>
        Type Parameters:
        T1 - type of the first element in the resulting triples
        T2 - type of the second element in the resulting triples
        T3 - type of the third element in the resulting triples
        Parameters:
        unzipper - a function that maps elements of this Traversable to triples
        Returns:
        a Tuple3 containing three Traversable collections with the split elements
      • update

        default Stream<T> update​(int index,
                                 T element)
        Description copied from interface: Seq
        Returns a new Seq with the element at the specified index replaced by the given value.
        Specified by:
        update in interface LinearSeq<T>
        Specified by:
        update in interface Seq<T>
        Parameters:
        index - the index of the element to update
        element - the new element to set at the specified index
        Returns:
        a new Seq with the updated element
      • update

        default Stream<T> update​(int index,
                                 @NonNull java.util.function.Function<? super T,​? extends T> updater)
        Description copied from interface: Seq
        Returns a new Seq with the element at the specified index updated using the given function.
        Specified by:
        update in interface LinearSeq<T>
        Specified by:
        update in interface Seq<T>
        Parameters:
        index - the index of the element to update
        updater - a function that computes the new element from the existing element
        Returns:
        a new Seq with the element at index transformed by updater
      • zip

        default <U> Stream<Tuple2<T,​U>> zip​(@NonNull java.lang.Iterable<? extends U> that)
        Description copied from interface: Traversable
        Returns a Traversable formed by pairing elements of this Traversable with elements of another Iterable. Pairing stops when either collection runs out of elements; any remaining elements in the longer collection are ignored.

        The length of the resulting Traversable is the minimum of the lengths of this Traversable and that.

        Specified by:
        zip in interface LinearSeq<T>
        Specified by:
        zip in interface Seq<T>
        Specified by:
        zip in interface Traversable<T>
        Type Parameters:
        U - the type of elements in the second half of each pair
        Parameters:
        that - an Iterable providing the second element of each pair
        Returns:
        a new Traversable containing pairs of corresponding elements
      • zipWith

        default <U,​R> Stream<R> zipWith​(@NonNull java.lang.Iterable<? extends U> that,
                                              java.util.function.BiFunction<? super T,​? super U,​? extends R> mapper)
        Description copied from interface: Traversable
        Returns a Traversable by combining elements of this Traversable with elements of another Iterable using a mapping function. Pairing stops when either collection runs out of elements.

        The length of the resulting Traversable is the minimum of the lengths of this Traversable and that.

        Specified by:
        zipWith in interface LinearSeq<T>
        Specified by:
        zipWith in interface Seq<T>
        Specified by:
        zipWith in interface Traversable<T>
        Type Parameters:
        U - the type of elements in the second parameter of the mapper
        R - the type of elements in the resulting Traversable
        Parameters:
        that - an Iterable providing the second parameter of the mapper
        mapper - a function that combines elements from this and that into a new element
        Returns:
        a new Traversable containing mapped elements
      • zipAll

        default <U> Stream<Tuple2<T,​U>> zipAll​(@NonNull java.lang.Iterable<? extends U> iterable,
                                                     T thisElem,
                                                     U thatElem)
        Description copied from interface: Traversable
        Returns a Traversable formed by pairing elements of this Traversable with elements of another Iterable, filling in placeholder elements when one collection is shorter than the other.

        The length of the resulting Traversable is the maximum of the lengths of this Traversable and that.

        If this Traversable is shorter than that, thisElem is used as a filler. Conversely, if that is shorter, thatElem is used.

        Specified by:
        zipAll in interface LinearSeq<T>
        Specified by:
        zipAll in interface Seq<T>
        Specified by:
        zipAll in interface Traversable<T>
        Type Parameters:
        U - the type of elements in the second half of each pair
        Parameters:
        iterable - an Iterable providing the second element of each pair
        thisElem - the element used to fill missing values if this Traversable is shorter than that
        thatElem - the element used to fill missing values if that is shorter than this Traversable
        Returns:
        a new Traversable containing pairs of elements, including fillers as needed
      • zipWithIndex

        default <U> Stream<U> zipWithIndex​(@NonNull java.util.function.BiFunction<? super T,​? super java.lang.Integer,​? extends U> mapper)
        Description copied from interface: Traversable
        Zips this Traversable with its indices and maps the resulting pairs using the provided mapper.
        Specified by:
        zipWithIndex in interface LinearSeq<T>
        Specified by:
        zipWithIndex in interface Seq<T>
        Specified by:
        zipWithIndex in interface Traversable<T>
        Type Parameters:
        U - the type of elements in the resulting Traversable
        Parameters:
        mapper - a function mapping an element and its index to a new element
        Returns:
        a new Traversable containing the mapped elements
      • extend

        default Stream<T> extend​(T next)
        Extends (continues) this Stream with a constantly repeated value.
        Parameters:
        next - value with which the stream should be extended
        Returns:
        new Stream composed from this stream extended with a Stream of provided value
      • extend

        default Stream<T> extend​(@NonNull java.util.function.Supplier<? extends T> nextSupplier)
        Extends (continues) this Stream with values provided by a Supplier
        Parameters:
        nextSupplier - a supplier which will provide values for extending a stream
        Returns:
        new Stream composed from this stream extended with values provided by the supplier
      • extend

        default Stream<T> extend​(@NonNull java.util.function.Function<? super T,​? extends T> nextFunction)
        Extends (continues) this Stream with a Stream of values created by applying consecutively provided Function to the last element of the original Stream.
        Parameters:
        nextFunction - a function which calculates the next value basing on the previous value
        Returns:
        new Stream composed from this stream extended with values calculated by the provided function