Class PriorityQueue<T>

    • Field Detail

      • comparator

        private final java.util.Comparator<? super T> comparator
      • size

        private final int size
    • Constructor Detail

      • PriorityQueue

        private PriorityQueue​(java.util.Comparator<? super T> comparator,
                              Seq<PriorityQueueBase.Node<T>> forest,
                              int size)
    • Method Detail

      • collect

        public <R> PriorityQueue<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 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
      • enqueue

        public PriorityQueue<T> enqueue​(T element)
        Enqueues a new element.
        Specified by:
        enqueue in class AbstractQueue<T,​PriorityQueue<T>>
        Parameters:
        element - The new element
        Returns:
        a new PriorityQueue instance, containing the new element
      • enqueueAll

        public PriorityQueue<T> enqueueAll​(java.lang.Iterable<? extends T> elements)
        Enqueues the given elements. A queue has FIFO order, i.e. the first of the given elements is the first which will be retrieved.
        Specified by:
        enqueueAll in class AbstractQueue<T,​PriorityQueue<T>>
        Parameters:
        elements - An PriorityQueue of elements, may be empty
        Returns:
        a new PriorityQueue instance, containing the new elements
        Throws:
        java.lang.NullPointerException - if elements is null
      • head

        public T head()
        Returns the first element of a non-empty PriorityQueue.
        Specified by:
        head in interface Traversable<T>
        Returns:
        The first element of this PriorityQueue.
        Throws:
        java.util.NoSuchElementException - if this is empty
      • merge

        public PriorityQueue<T> merge​(PriorityQueue<T> target)
        Merges this PriorityQueue with another PriorityQueue. Both queues must use the same comparator.
        Parameters:
        target - A PriorityQueue
        Returns:
        A new PriorityQueue containing elements from both queues in priority order.
      • isAsync

        public boolean isAsync()
        A PriorityQueue is computed synchronously.
        Specified by:
        isAsync in interface Value<T>
        Returns:
        false
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: Traversable
        Checks if this Traversable contains no elements.
        Specified by:
        isEmpty in interface Traversable<T>
        Specified by:
        isEmpty in interface Value<T>
        Returns:
        true if empty, false otherwise
      • isLazy

        public boolean isLazy()
        A PriorityQueue is computed eagerly.
        Specified by:
        isLazy in interface Value<T>
        Returns:
        false
      • isOrdered

        public boolean isOrdered()
        Description copied from interface: Traversable
        Indicates whether this Traversable is ordered according to its natural or specified order.
        Specified by:
        isOrdered in interface Traversable<T>
        Returns:
        true if this Traversable is ordered, false otherwise
      • empty

        public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> empty()
        Returns the empty PriorityQueue.
        Type Parameters:
        T - Component type
        Returns:
        The empty PriorityQueue.
      • empty

        public static <T> PriorityQueue<T> empty​(java.util.Comparator<? super T> comparator)
        Returns an empty PriorityQueue with the given comparator.
        Type Parameters:
        T - Component type
        Parameters:
        comparator - The comparator used to order the elements
        Returns:
        The empty PriorityQueue.
      • collector

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

        public static <T> PriorityQueue<T> narrow​(PriorityQueue<? extends T> queue)
        Narrows a PriorityQueue<? extends T> to PriorityQueue<T> via a type-safe cast. Safe here because the queue is immutable and no elements can be added that would violate the type (covariance)
        Type Parameters:
        T - the target element type
        Parameters:
        queue - the queue to narrow
        Returns:
        the same queue viewed as PriorityQueue<T>
      • of

        public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of​(T element)
        Returns a singleton PriorityQueue, i.e. a PriorityQueue of one element.
        Type Parameters:
        T - Component type
        Parameters:
        element - The element
        Returns:
        A new PriorityQueue instance containing the given element
      • of

        public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> of​(T... elements)
        Creates a PriorityQueue of the given elements.
        Type Parameters:
        T - Component type
        Parameters:
        elements - Zero or more elements.
        Returns:
        A PriorityQueue containing the given elements.
        Throws:
        java.lang.NullPointerException - if elements is null
      • of

        public static <T> PriorityQueue<T> of​(java.util.Comparator<? super T> comparator,
                                              T element)
        Returns a singleton PriorityQueue, i.e. a PriorityQueue of one element with the given comparator.
        Type Parameters:
        T - Component type
        Parameters:
        comparator - The comparator used to order the elements
        element - The element
        Returns:
        A new PriorityQueue instance containing the given element
      • of

        public static <T> PriorityQueue<T> of​(@NonNull java.util.Comparator<? super T> comparator,
                                              T @NonNull ... elements)
        Creates a PriorityQueue of the given elements with the given comparator.
        Type Parameters:
        T - Component type
        Parameters:
        comparator - The comparator used to order the elements
        elements - Zero or more elements.
        Returns:
        A PriorityQueue containing the given elements.
        Throws:
        java.lang.NullPointerException - if comparator or elements is null
      • ofAll

        public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Creates a PriorityQueue of the given elements.
        Type Parameters:
        T - Component type
        Parameters:
        elements - An Iterable of elements.
        Returns:
        A PriorityQueue containing the given elements in priority order.
        Throws:
        java.lang.NullPointerException - if elements is null
      • ofAll

        public static <T> PriorityQueue<T> ofAll​(@NonNull java.util.Comparator<? super T> comparator,
                                                 @NonNull java.lang.Iterable<? extends T> elements)
        Creates a PriorityQueue of the given elements with the given comparator.
        Type Parameters:
        T - Component type
        Parameters:
        comparator - The comparator used to order the elements
        elements - An Iterable of elements.
        Returns:
        A PriorityQueue containing the given elements in priority order.
        Throws:
        java.lang.NullPointerException - if comparator or elements is null
      • ofAll

        public static <T extends java.lang.Comparable<? super T>> PriorityQueue<T> ofAll​(java.util.stream.Stream<? extends T> javaStream)
        Creates a PriorityQueue from a Stream.
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        javaStream - A Stream
        Returns:
        A PriorityQueue containing the given elements in priority order.
      • ofAll

        public static <T> PriorityQueue<T> ofAll​(java.util.Comparator<? super T> comparator,
                                                 java.util.stream.Stream<? extends T> javaStream)
        Creates a PriorityQueue from a Stream with the given comparator.
        Type Parameters:
        T - Component type of the Stream.
        Parameters:
        comparator - The comparator used to order the elements
        javaStream - A Stream
        Returns:
        A PriorityQueue containing the given elements in priority order.
      • tabulate

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

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

        public List<T> toList()
        Description copied from interface: Value
        Converts this to a List.
        Specified by:
        toList in interface Value<T>
        Returns:
        A new List.
      • distinct

        public PriorityQueue<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 Traversable<T>
        Returns:
        a new Traversable without duplicate elements
      • distinctBy

        public PriorityQueue<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 Traversable<T>
        Parameters:
        comparator - a comparator used to determine equality of elements
        Returns:
        a new Traversable with duplicates removed
      • distinctBy

        public <U> PriorityQueue<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 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
      • drop

        public PriorityQueue<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 Traversable<T>
        Parameters:
        n - the number of elements to drop
        Returns:
        a new instance excluding the first n elements
      • dropRight

        public PriorityQueue<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 Traversable<T>
        Parameters:
        n - the number of elements to drop from the end
        Returns:
        a new instance excluding the last n elements
      • dropWhile

        public PriorityQueue<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 Traversable<T>
        Specified by:
        dropWhile in class AbstractQueue<T,​PriorityQueue<T>>
        Parameters:
        predicate - a condition tested on each element
        Returns:
        a new instance starting from the first element not matching the predicate
      • filter

        public PriorityQueue<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 Traversable<T>
        Parameters:
        predicate - the condition to test elements
        Returns:
        a traversable with elements matching the predicate
      • flatMap

        public <U> PriorityQueue<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 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
      • flatMap

        public <U> PriorityQueue<U> flatMap​(@NonNull java.util.Comparator<U> comparator,
                                            @NonNull java.util.function.Function<? super T,​? extends java.lang.Iterable<? extends U>> mapper)
        Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function and flattened with the given comparator.
        Type Parameters:
        U - The result type
        Parameters:
        comparator - The comparator used to order the elements
        mapper - A function which maps elements of this PriorityQueue to Iterables of type U
        Returns:
        A new PriorityQueue
        Throws:
        java.lang.NullPointerException - if comparator or mapper is null
      • foldRight

        public <U> U foldRight​(U zero,
                               @NonNull java.util.function.BiFunction<? super T,​? super U,​? extends U> accumulator)
        Accumulates the elements of this PriorityQueue by successively calling the given function f from the right, starting with a value zero of type B.

        Example: PriorityQueue.of("a", "b", "c").foldRight("", (x, xs) -> x + xs) = "abc"

        Specified by:
        foldRight in interface Foldable<T>
        Specified by:
        foldRight in interface Traversable<T>
        Type Parameters:
        U - the type of the accumulated result
        Parameters:
        zero - Value to start the accumulation with.
        accumulator - The accumulator function.
        Returns:
        an accumulated version of this.
        Throws:
        java.lang.NullPointerException - if f is null
      • groupBy

        public <C> Map<C,​? extends PriorityQueue<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 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

        public Iterator<? extends PriorityQueue<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 Traversable<T>
        Parameters:
        size - the block size; must be positive
        Returns:
        an Iterator over blocks of elements
      • hasDefiniteSize

        public boolean hasDefiniteSize()
        Checks if this PriorityQueue is known to have a finite size.

        This method should be implemented by classes only, i.e. not by interfaces.

        Specified by:
        hasDefiniteSize in interface Traversable<T>
        Returns:
        true, if this PriorityQueue is known to have a finite size, false otherwise.
      • init

        public PriorityQueue<T> init()
        Dual of tail(), returning all elements except the last.
        Specified by:
        init in interface Traversable<T>
        Specified by:
        init in class AbstractQueue<T,​PriorityQueue<T>>
        Returns:
        a new instance containing all elements except the last.
        Throws:
        java.lang.UnsupportedOperationException - if this is empty
      • isTraversableAgain

        public boolean isTraversableAgain()
        Checks if this PriorityQueue can be repeatedly traversed.

        This method should be implemented by classes only, i.e. not by interfaces.

        Specified by:
        isTraversableAgain in interface Traversable<T>
        Returns:
        true, if this PriorityQueue is known to be traversable repeatedly, false otherwise.
      • last

        public 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
      • map

        public <U> PriorityQueue<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 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

        public <U> PriorityQueue<U> mapTo​(U value)
        Description copied from interface: Value
        Maps the underlying value to another fixed value.
        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
      • mapToVoid

        public PriorityQueue<java.lang.Void> mapToVoid()
        Description copied from interface: Value
        Maps the underlying value to Void
        Specified by:
        mapToVoid in interface Traversable<T>
        Specified by:
        mapToVoid in interface Value<T>
        Returns:
        A new value of type Void
      • map

        public <U> PriorityQueue<U> map​(@NonNull java.util.Comparator<U> comparator,
                                        @NonNull java.util.function.Function<? super T,​? extends U> mapper)
        Returns a new PriorityQueue that contains the elements of this PriorityQueue transformed by the given mapper function with the given comparator.
        Type Parameters:
        U - The result type
        Parameters:
        comparator - The comparator used to order the elements
        mapper - A function which maps elements of this PriorityQueue to elements of type U
        Returns:
        A new PriorityQueue
        Throws:
        java.lang.NullPointerException - if comparator or mapper is null
      • orElse

        public PriorityQueue<T> orElse​(java.lang.Iterable<? extends T> other)
        Returns this PriorityQueue if it is nonempty, otherwise PriorityQueue created from iterable, using existing comparator.
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        other - An alternative Traversable
        Returns:
        this PriorityQueue if it is nonempty, otherwise PriorityQueue created from iterable, using existing comparator.
      • orElse

        public PriorityQueue<T> orElse​(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
        Returns this PriorityQueue if it is nonempty, otherwise PriorityQueue created from result of evaluating supplier, using existing comparator.
        Specified by:
        orElse in interface Traversable<T>
        Parameters:
        supplier - An alternative Traversable
        Returns:
        this PriorityQueue if it is nonempty, otherwise PriorityQueue created from result of evaluating supplier, using existing comparator.
      • partition

        public Tuple2<? extends PriorityQueue<T>,​? extends PriorityQueue<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 Traversable<T>
        Parameters:
        predicate - a predicate used to classify elements
        Returns:
        a Tuple2 containing the two resulting Traversable instances
      • replace

        public PriorityQueue<T> replace​(@NonNull T currentElement,
                                        @NonNull T newElement)
        Description copied from interface: Traversable
        Replaces the first occurrence of currentElement with newElement, if it exists.
        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

        public PriorityQueue<T> replaceAll​(@NonNull T currentElement,
                                           @NonNull T newElement)
        Description copied from interface: Traversable
        Replaces all occurrences of currentElement with newElement.
        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
      • scan

        public PriorityQueue<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 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

        public <U> PriorityQueue<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 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

        public <U> PriorityQueue<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 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
      • slideBy

        public Iterator<? extends PriorityQueue<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 Traversable<T>
        Parameters:
        classifier - A function classifying elements into groups
        Returns:
        An Iterator of windows (grouped elements)
      • sliding

        public Iterator<? extends PriorityQueue<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 Traversable<T>
        Parameters:
        size - a positive window size
        Returns:
        An Iterator of windows, each containing up to size elements
      • sliding

        public Iterator<? extends PriorityQueue<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 Traversable<T>
        Parameters:
        size - a positive window size
        step - a positive step size
        Returns:
        an Iterator of windows with the given size and step
      • span

        public Tuple2<? extends PriorityQueue<T>,​? extends PriorityQueue<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 Traversable<T>
        Parameters:
        predicate - a predicate used to determine the prefix
        Returns:
        a Tuple containing the prefix and remainder
      • take

        public PriorityQueue<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 Traversable<T>
        Parameters:
        n - the number of elements to take
        Returns:
        a new Traversable containing the first n elements
      • takeRight

        public PriorityQueue<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 Traversable<T>
        Parameters:
        n - the number of elements to take from the end
        Returns:
        a new Traversable containing the last n elements
      • takeUntil

        public PriorityQueue<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 Traversable<T>
        Specified by:
        takeUntil in class AbstractQueue<T,​PriorityQueue<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
      • unzip

        public <T1,​T2> Tuple2<? extends PriorityQueue<T1>,​? extends PriorityQueue<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 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

        public <T1,​T2,​T3> Tuple3<? extends PriorityQueue<T1>,​? extends PriorityQueue<T2>,​? extends PriorityQueue<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 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
      • zip

        public <U> PriorityQueue<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 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

        public <U,​R> PriorityQueue<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 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

        public <U> PriorityQueue<Tuple2<T,​U>> zipAll​(@NonNull java.lang.Iterable<? extends U> that,
                                                           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 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
        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

        public PriorityQueue<Tuple2<T,​java.lang.Integer>> zipWithIndex()
        Description copied from interface: Traversable
        Zips this Traversable with its indices, starting at 0.
        Specified by:
        zipWithIndex in interface Traversable<T>
        Returns:
        a new Traversable containing each element paired with its index
      • zipWithIndex

        public <U> PriorityQueue<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 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
      • stringPrefix

        public 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.
      • equals

        public boolean equals​(java.lang.Object o)
        Description copied from interface: Traversable
        Determines whether this collection is equal to the given object.

        In Vavr, there are four basic collection types:

        • Seq – sequential elements
        • Set – distinct elements
        • Map – key-value pairs
        • Multimap – keys mapped to multiple values
        Two collections are considered equal if and only if:
        • They are of the same collection type (Seq, Set, Map, Multimap)
        • They contain the same elements
        • For Seq, the element order is the same

        For Map and Multimap, two entries (key1, value1) and (key2, value2) are equal if both their keys and values are equal.

        Additional notes:

        • No collection equals null (e.g., Queue(1) != null)
        • Null elements are allowed and treated as expected (e.g., List(null, 1) == Stream(null, 1), HashMap((null,1)) == LinkedHashMap((null,1)))
        • Element order matters only for Seq
        • Other collection classes are equal if their types and elements (in iteration order) are equal
        • Iterators are compared by reference only
        Specified by:
        equals in interface Traversable<T>
        Specified by:
        equals in interface Value<T>
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the object to compare with, may be null
        Returns:
        true if the collections are equal according to the rules above, false otherwise
      • hashCode

        public int hashCode()
        Description copied from interface: Traversable
        Returns the hash code of this collection.

        Vavr distinguishes between collections with predictable iteration order (like Seq) and collections with arbitrary iteration order (like Set, Map, and Multimap). In all cases, the hash of an empty collection is defined as 1.

        For collections with predictable iteration order, the hash is computed as:

        
         int hash = 1;
         for (T t : this) {
             hash = hash * 31 + Objects.hashCode(t);
         }
         

        For collections with arbitrary iteration order, the hash is computed to be independent of element order:

        
         int hash = 1;
         for (T t : this) {
             hash += Objects.hashCode(t);
         }
         

        Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as HashMap keys), caching can be done externally using a wrapper, for example:

        {@code
         public final class Hashed {
             private final K key;
             private final Lazy hashCode;
        
             public Hashed(K key) {
                 this.key = key;
                 this.hashCode = Lazy.of(() -> Objects.hashCode(key));
             }
        
             public K key() { return key; }
        Specified by:
        hashCode in interface Traversable<T>
        Specified by:
        hashCode in interface Value<T>
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code of this collection
      • comparator

        public java.util.Comparator<T> comparator()
        Description copied from interface: Ordered
        Returns the comparator that governs the ordering of elements in this collection. The returned comparator must be consistent with the collection's iteration order.
        Specified by:
        comparator in interface Ordered<T>
        Returns:
        the comparator defining the element order