Class HashSet<T>

  • Type Parameters:
    T - Component type
    All Implemented Interfaces:
    Foldable<T>, Set<T>, Traversable<T>, Function1<T,​java.lang.Boolean>, Value<T>, java.io.Serializable, java.lang.Iterable<T>, java.util.function.Function<T,​java.lang.Boolean>

    public final class HashSet<T>
    extends java.lang.Object
    implements Set<T>, java.io.Serializable
    An immutable HashSet implementation.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  HashSet.SerializationProxy<T>
      A serialization proxy which, in this context, is used to deserialize immutable, linked Lists with final instance fields.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HashSet<T> add​(T element)
      Returns a new set containing all elements of this set plus the given element, if it was not already present.
      HashSet<T> addAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Returns a new set containing all elements of this set plus the given elements, excluding duplicates.
      private static <T> HashArrayMappedTrie<T,​T> addAll​(HashArrayMappedTrie<T,​T> initial, java.lang.Iterable<? extends T> additional)  
      <R> HashSet<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>,​HashSet<T>> collector()
      Returns a Collector which may be used in conjunction with Stream.collect(java.util.stream.Collector) to obtain a HashSet.
      boolean contains​(T element)
      Shortcut for exists(e -> Objects.equals(e, element)), tests if the given element is contained.
      HashSet<T> diff​(@NonNull Set<? extends T> elements)
      Returns a new set containing all elements of this set except those in the given set.
      HashSet<T> distinct()
      Returns a new Traversable containing the elements of this instance with all duplicates removed.
      HashSet<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.
      <U> HashSet<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.
      HashSet<T> drop​(int n)
      Returns a new Traversable without the first n elements, or an empty instance if this contains fewer than n elements.
      HashSet<T> dropRight​(int n)
      Returns a new Traversable without the last n elements, or an empty instance if this contains fewer than n elements.
      HashSet<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.
      HashSet<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> HashSet<T> empty()
      Returns the empty HashSet.
      boolean equals​(java.lang.Object o)
      Determines whether this collection is equal to the given object.
      static <T> HashSet<T> fill​(int n, @NonNull java.util.function.Supplier<? extends T> s)
      Returns a HashSet containing tuples returned by n calls to a given Supplier s.
      HashSet<T> filter​(@NonNull java.util.function.Predicate<? super T> predicate)
      Returns a new traversable containing only the elements that satisfy the given predicate.
      <U> HashSet<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.
      <U> U foldRight​(U zero, @NonNull java.util.function.BiFunction<? super T,​? super U,​? extends U> f)
      Folds the elements of this structure from the right, starting with the given zero value and successively applying the combine function to each element.
      <C> Map<C,​HashSet<T>> groupBy​(@NonNull java.util.function.Function<? super T,​? extends C> classifier)
      Groups elements of this Traversable based on a classifier function.
      Iterator<HashSet<T>> grouped​(int size)
      Splits this Traversable into consecutive blocks of the given size.
      boolean hasDefiniteSize()
      Indicates whether this Traversable has a known finite size.
      int hashCode()
      Returns the hash code of this collection.
      T head()
      Returns the first element of this non-empty Traversable.
      Option<T> headOption()
      Returns the first element of this Traversable as an Option.
      HashSet<T> init()
      Returns all elements of this Traversable except the last one.
      Option<HashSet<T>> initOption()
      Returns all elements of this Traversable except the last one, wrapped in an Option.
      HashSet<T> intersect​(@NonNull Set<? extends T> elements)
      Returns a new set containing only the elements present in both this set and the given set.
      boolean isAsync()
      A HashSet is computed synchronously.
      boolean isEmpty()
      Checks if this Traversable contains no elements.
      boolean isLazy()
      A HashSet is computed eagerly.
      boolean isTraversableAgain()
      Checks if this Traversable can be traversed multiple times without side effects.
      @NonNull Iterator<T> iterator()
      Returns an iterator over the elements of this Traversable, implemented via Traversable.head() and Traversable.tail().
      T last()
      Returns the last element of this Traversable.
      int length()
      Returns the number of elements in this Traversable.
      <U> HashSet<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.
      <U> HashSet<U> mapTo​(U value)
      Maps the underlying value to another fixed value.
      HashSet<java.lang.Void> mapToVoid()
      Maps the underlying value to Void
      java.lang.String mkString​(java.lang.CharSequence prefix, java.lang.CharSequence delimiter, java.lang.CharSequence suffix)
      Concatenates the string representations of all elements in this Traversable with a prefix, delimiter, and suffix.
      static <T> HashSet<T> narrow​(HashSet<? extends T> hashSet)
      Narrows a HashSet<? extends T> to HashSet<T> via a type-safe cast.
      static <T> HashSet<T> of​(T element)
      Returns a singleton HashSet, i.e.
      static <T> HashSet<T> of​(T @NonNull ... elements)
      Creates a HashSet of the given elements.
      static HashSet<java.lang.Boolean> ofAll​(boolean @NonNull ... elements)
      Creates a HashSet from boolean values.
      static HashSet<java.lang.Byte> ofAll​(byte @NonNull ... elements)
      Creates a HashSet from byte values.
      static HashSet<java.lang.Character> ofAll​(char @NonNull ... elements)
      Creates a HashSet from char values.
      static HashSet<java.lang.Double> ofAll​(double @NonNull ... elements)
      Creates a HashSet from double values.
      static HashSet<java.lang.Float> ofAll​(float @NonNull ... elements)
      Creates a HashSet from float values.
      static HashSet<java.lang.Integer> ofAll​(int @NonNull ... elements)
      Creates a HashSet from int values.
      static HashSet<java.lang.Long> ofAll​(long @NonNull ... elements)
      Creates a HashSet from long values.
      static HashSet<java.lang.Short> ofAll​(short @NonNull ... elements)
      Creates a HashSet from short values.
      static <T> HashSet<T> ofAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Creates a HashSet of the given elements.
      static <T> HashSet<T> ofAll​(java.util.stream.Stream<? extends T> javaStream)
      Creates a HashSet that contains the elements of the given Stream.
      HashSet<T> orElse​(@NonNull java.lang.Iterable<? extends T> other)
      Returns this Traversable if it is non-empty; otherwise, returns the given alternative.
      HashSet<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.
      Tuple2<HashSet<T>,​HashSet<T>> partition​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this Traversable into two partitions according to a predicate.
      HashSet<T> peek​(@NonNull java.util.function.Consumer<? super T> action)
      Performs the given action on the first element if this is an eager implementation.
      static HashSet<java.lang.Character> range​(char from, char toExclusive)
      Creates a HashSet of char numbers starting from from, extending to toExclusive - 1.
      static HashSet<java.lang.Integer> range​(int from, int toExclusive)
      Creates a HashSet of int numbers starting from from, extending to toExclusive - 1.
      static HashSet<java.lang.Long> range​(long from, long toExclusive)
      Creates a HashSet of long numbers starting from from, extending to toExclusive - 1.
      static HashSet<java.lang.Character> rangeBy​(char from, char toExclusive, int step)
      Creates a HashSet of char numbers starting from from, extending to toExclusive - 1, with step.
      static HashSet<java.lang.Double> rangeBy​(double from, double toExclusive, double step)
      Creates a HashSet of double numbers starting from from, extending to toExclusive - 1, with step.
      static HashSet<java.lang.Integer> rangeBy​(int from, int toExclusive, int step)
      Creates a HashSet of int numbers starting from from, extending to toExclusive - 1, with step.
      static HashSet<java.lang.Long> rangeBy​(long from, long toExclusive, long step)
      Creates a HashSet of long numbers starting from from, extending to toExclusive - 1, with step.
      static HashSet<java.lang.Character> rangeClosed​(char from, char toInclusive)
      Creates a HashSet of char numbers starting from from, extending to toInclusive.
      static HashSet<java.lang.Integer> rangeClosed​(int from, int toInclusive)
      Creates a HashSet of int numbers starting from from, extending to toInclusive.
      static HashSet<java.lang.Long> rangeClosed​(long from, long toInclusive)
      Creates a HashSet of long numbers starting from from, extending to toInclusive.
      static HashSet<java.lang.Character> rangeClosedBy​(char from, char toInclusive, int step)
      Creates a HashSet of char numbers starting from from, extending to toInclusive, with step.
      static HashSet<java.lang.Double> rangeClosedBy​(double from, double toInclusive, double step)
      Creates a HashSet of double numbers starting from from, extending to toInclusive, with step.
      static HashSet<java.lang.Integer> rangeClosedBy​(int from, int toInclusive, int step)
      Creates a HashSet of int numbers starting from from, extending to toInclusive, with step.
      static HashSet<java.lang.Long> rangeClosedBy​(long from, long toInclusive, long step)
      Creates a HashSet of long numbers starting from from, extending to toInclusive, with step.
      private void readObject​(java.io.ObjectInputStream stream)
      readObject method for the serialization proxy pattern.
      HashSet<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.
      HashSet<T> remove​(T element)
      Returns a new set with the given element removed, if it was present.
      HashSet<T> removeAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Returns a new set with all given elements removed, if present.
      HashSet<T> replace​(T currentElement, T newElement)
      Replaces the first occurrence of currentElement with newElement, if it exists.
      HashSet<T> replaceAll​(T currentElement, T newElement)
      Replaces all occurrences of currentElement with newElement.
      HashSet<T> retainAll​(@NonNull java.lang.Iterable<? extends T> elements)
      Retains only the elements from this Traversable that are contained in the given elements.
      HashSet<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.
      <U> HashSet<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.
      <U> HashSet<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.
      Iterator<HashSet<T>> slideBy​(@NonNull java.util.function.Function<? super T,​?> classifier)
      Partitions this Traversable into consecutive non-overlapping windows according to a classification function.
      Iterator<HashSet<T>> sliding​(int size)
      Slides a window of a given size over this Traversable with a step size of 1.
      Iterator<HashSet<T>> sliding​(int size, int step)
      Slides a window of a specific size with a given step over this Traversable.
      Tuple2<HashSet<T>,​HashSet<T>> span​(@NonNull java.util.function.Predicate<? super T> predicate)
      Splits this Traversable into a prefix and remainder according to the given predicate.
      java.lang.String stringPrefix()
      Returns the name of this Value type, which is used by toString().
      static <T> HashSet<T> tabulate​(int n, @NonNull java.util.function.Function<? super java.lang.Integer,​? extends T> f)
      Returns an HashSet containing n values of a given Function f over a range of integer values from 0 to n - 1.
      HashSet<T> tail()
      Returns a new Traversable without its first element.
      Option<HashSet<T>> tailOption()
      Returns a new Traversable without its first element as an Option.
      HashSet<T> take​(int n)
      Returns the first n elements of this Traversable, or all elements if n exceeds the length.
      HashSet<T> takeRight​(int n)
      Returns the last n elements of this Traversable, or all elements if n exceeds the length.
      HashSet<T> takeUntil​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from this Traversable until the given predicate holds for an element.
      HashSet<T> takeWhile​(@NonNull java.util.function.Predicate<? super T> predicate)
      Takes elements from this Traversable while the given predicate holds.
      java.util.HashSet<T> toJavaSet()
      Converts this Vavr set to a java.util.Set, preserving insertion or sort order.
      java.lang.String toString()
      Clarifies that values have a proper toString() method implemented.
      <U> U transform​(java.util.function.Function<? super HashSet<T>,​? extends U> f)
      Transforms this HashSet.
      HashSet<T> union​(@NonNull Set<? extends T> elements)
      Returns a new set containing all distinct elements from this set and the given set.
      <T1,​T2>
      Tuple2<HashSet<T1>,​HashSet<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.
      <T1,​T2,​T3>
      Tuple3<HashSet<T1>,​HashSet<T2>,​HashSet<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.
      private java.lang.Object writeReplace()
      writeReplace method for the serialization proxy pattern.
      <U> HashSet<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.
      <U> HashSet<Tuple2<T,​U>> zipAll​(@NonNull java.lang.Iterable<? extends U> that, 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.
      <U,​R>
      HashSet<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.
      HashSet<Tuple2<T,​java.lang.Integer>> zipWithIndex()
      Zips this Traversable with its indices, starting at 0.
      <U> HashSet<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.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • empty

        public static <T> HashSet<T> empty()
        Returns the empty HashSet.
        Type Parameters:
        T - Component type
        Returns:
        The empty HashSet.
      • collector

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

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

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

        @SafeVarargs
        public static <T> HashSet<T> of​(T @NonNull ... elements)
        Creates a HashSet of the given elements.
        HashSet.of(1, 2, 3, 4)
        Type Parameters:
        T - Component type of the HashSet.
        Parameters:
        elements - Zero or more elements.
        Returns:
        A set containing the given elements.
        Throws:
        java.lang.NullPointerException - if elements is null
      • tabulate

        public static <T> HashSet<T> tabulate​(int n,
                                              @NonNull java.util.function.Function<? super java.lang.Integer,​? extends T> f)
        Returns an HashSet 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 HashSet
        Parameters:
        n - The number of elements in the HashSet
        f - The Function computing element values
        Returns:
        An HashSet consisting of elements f(0),f(1), ..., f(n - 1)
        Throws:
        java.lang.NullPointerException - if f is null
      • fill

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

        public static <T> HashSet<T> ofAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Creates a HashSet of the given elements.
        Type Parameters:
        T - The value type
        Parameters:
        elements - Set elements
        Returns:
        A new HashSet containing the given entries
      • ofAll

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

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

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

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

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

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

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

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

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

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

        Examples:

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

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

        Examples:

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

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

        Examples:

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

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

        Examples:

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

        @GwtIncompatible
        public static HashSet<java.lang.Double> rangeBy​(double from,
                                                        double toExclusive,
                                                        double step)
        Creates a HashSet of double numbers starting from from, extending to toExclusive - 1, with step.

        Examples:

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

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

        Examples:

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

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

        Examples:

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

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

        Examples:

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

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

        Examples:

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

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

        Examples:

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

        public static HashSet<java.lang.Character> rangeClosedBy​(char from,
                                                                 char toInclusive,
                                                                 int step)
        Creates a HashSet of char numbers starting from from, extending to toInclusive, with step.

        Examples:

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

        @GwtIncompatible
        public static HashSet<java.lang.Double> rangeClosedBy​(double from,
                                                              double toInclusive,
                                                              double step)
        Creates a HashSet of double numbers starting from from, extending to toInclusive, with step.

        Examples:

         
         HashSet.rangeClosedBy(1.0, 3.0, 1.0)  // = HashSet(1.0, 2.0, 3.0)
         HashSet.rangeClosedBy(1.0, 4.0, 2.0)  // = HashSet(1.0, 3.0)
         HashSet.rangeClosedBy(4.0, 1.0, -2.0) // = HashSet(4.0, 2.0)
         HashSet.rangeClosedBy(4.0, 1.0, 2.0)  // = HashSet()
         
         
        Parameters:
        from - the first double
        toInclusive - the last double
        step - the step
        Returns:
        a range of double values as specified or the empty range if
        from > toInclusive and step > 0 or
        from < toInclusive and step < 0
        Throws:
        java.lang.IllegalArgumentException - if step is zero
      • rangeClosed

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

        Examples:

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

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

        Examples:

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

        public HashSet<T> add​(T element)
        Description copied from interface: Set
        Returns a new set containing all elements of this set plus the given element, if it was not already present.
        Specified by:
        add in interface Set<T>
        Parameters:
        element - the element to add
        Returns:
        a new set including the element
      • addAll

        public HashSet<T> addAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Set
        Returns a new set containing all elements of this set plus the given elements, excluding duplicates.
        Specified by:
        addAll in interface Set<T>
        Parameters:
        elements - the elements to add
        Returns:
        a new set including the additional elements
      • collect

        public <R> HashSet<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 Set<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
      • contains

        public boolean contains​(T element)
        Description copied from interface: Value
        Shortcut for exists(e -> Objects.equals(e, element)), tests if the given element is contained.
        Specified by:
        contains in interface Set<T>
        Specified by:
        contains in interface Value<T>
        Parameters:
        element - An Object of type A, may be null.
        Returns:
        true, if element is contained, false otherwise.
      • diff

        public HashSet<T> diff​(@NonNull Set<? extends T> elements)
        Description copied from interface: Set
        Returns a new set containing all elements of this set except those in the given set.
        Specified by:
        diff in interface Set<T>
        Parameters:
        elements - the set of elements to remove
        Returns:
        a new set without the specified elements
      • distinct

        public HashSet<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 Set<T>
        Specified by:
        distinct in interface Traversable<T>
        Returns:
        a new Traversable without duplicate elements
      • distinctBy

        public HashSet<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 Set<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

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

        public HashSet<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 Set<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
      • dropRight

        public HashSet<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 Set<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
      • dropUntil

        public HashSet<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 Set<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

        public HashSet<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 Set<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
      • filter

        public HashSet<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 Set<T>
        Specified by:
        filter in interface Traversable<T>
        Parameters:
        predicate - the condition to test elements
        Returns:
        a traversable with elements matching the predicate
      • reject

        public HashSet<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 Set<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

        public <U> HashSet<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 Set<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
      • foldRight

        public <U> U foldRight​(U zero,
                               @NonNull java.util.function.BiFunction<? super T,​? super U,​? extends U> f)
        Description copied from interface: Foldable
        Folds the elements of this structure from the right, starting with the given zero value and successively applying the combine function to each element.

        Folding from the right means that elements are combined starting from the last element and associating each step with the accumulated result so far.

        Example:

        
         // Result: "!cba"
         List.of("a", "b", "c").foldRight("!", (x, acc) -> acc + x);
         
        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 - the initial value to start folding with
        f - a function that combines the next element and the accumulated value
        Returns:
        the folded result
      • groupBy

        public <C> Map<C,​HashSet<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 Set<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

        public Iterator<HashSet<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 Set<T>
        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()
        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.
      • head

        public T head()
        Description copied from interface: Traversable
        Returns the first element of this non-empty Traversable.
        Specified by:
        head in interface Traversable<T>
        Returns:
        the first element
      • headOption

        public Option<T> headOption()
        Description copied from interface: Traversable
        Returns the first element of this Traversable as an Option.
        Specified by:
        headOption in interface Traversable<T>
        Returns:
        Some(element) if non-empty, otherwise None
      • init

        public HashSet<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 Set<T>
        Specified by:
        init in interface Traversable<T>
        Returns:
        a new instance containing all elements except the last
      • intersect

        public HashSet<T> intersect​(@NonNull Set<? extends T> elements)
        Description copied from interface: Set
        Returns a new set containing only the elements present in both this set and the given set.
        Specified by:
        intersect in interface Set<T>
        Parameters:
        elements - the set to intersect with
        Returns:
        a new set with elements common to both sets
      • isAsync

        public boolean isAsync()
        A HashSet 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 HashSet is computed eagerly.
        Specified by:
        isLazy in interface Value<T>
        Returns:
        false
      • isTraversableAgain

        public 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

        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
      • length

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

        Equivalent to Traversable.size().

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

        public <U> HashSet<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 Set<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

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

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

        public java.lang.String mkString​(java.lang.CharSequence prefix,
                                         java.lang.CharSequence delimiter,
                                         java.lang.CharSequence suffix)
        Description copied from interface: Traversable
        Concatenates the string representations of all elements in this Traversable with a prefix, delimiter, and suffix.

        Example: List.of("a", "b", "c").mkString("Chars(", ", ", ")") = "Chars(a, b, c)"

        Specified by:
        mkString in interface Traversable<T>
        Parameters:
        prefix - a string prepended to the result
        delimiter - a string placed between elements
        suffix - a string appended to the result
        Returns:
        a new String containing the formatted concatenation of elements
      • orElse

        public HashSet<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 Set<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

        public HashSet<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 Set<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()
      • partition

        public Tuple2<HashSet<T>,​HashSet<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 Set<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

        public HashSet<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 Set<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
      • remove

        public HashSet<T> remove​(T element)
        Description copied from interface: Set
        Returns a new set with the given element removed, if it was present.
        Specified by:
        remove in interface Set<T>
        Parameters:
        element - the element to remove
        Returns:
        a new set without the specified element
      • removeAll

        public HashSet<T> removeAll​(@NonNull java.lang.Iterable<? extends T> elements)
        Description copied from interface: Set
        Returns a new set with all given elements removed, if present.
        Specified by:
        removeAll in interface Set<T>
        Parameters:
        elements - the elements to remove
        Returns:
        a new set without the specified elements
      • replace

        public HashSet<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 Set<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

        public HashSet<T> replaceAll​(T currentElement,
                                     T newElement)
        Description copied from interface: Traversable
        Replaces all occurrences of currentElement with newElement.
        Specified by:
        replaceAll in interface Set<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

        public HashSet<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 Set<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
      • scan

        public HashSet<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 Set<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

        public <U> HashSet<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 Set<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

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

        public Iterator<HashSet<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 Set<T>
        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<HashSet<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 Set<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

        public Iterator<HashSet<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 Set<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
      • span

        public Tuple2<HashSet<T>,​HashSet<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 Set<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
      • tail

        public HashSet<T> tail()
        Description copied from interface: Traversable
        Returns a new Traversable without its first element.
        Specified by:
        tail in interface Set<T>
        Specified by:
        tail in interface Traversable<T>
        Returns:
        a new Traversable containing all elements except the first
      • tailOption

        public Option<HashSet<T>> tailOption()
        Description copied from interface: Traversable
        Returns a new Traversable without its first element as an Option.
        Specified by:
        tailOption in interface Set<T>
        Specified by:
        tailOption in interface Traversable<T>
        Returns:
        Some(traversable) if non-empty, otherwise None
      • take

        public HashSet<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 Set<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
      • takeRight

        public HashSet<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 Set<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
      • takeUntil

        public HashSet<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 Set<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

        public HashSet<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 Set<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
      • transform

        public <U> U transform​(java.util.function.Function<? super HashSet<T>,​? extends U> f)
        Transforms this HashSet.
        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
      • toJavaSet

        public java.util.HashSet<T> toJavaSet()
        Description copied from interface: Set
        Converts this Vavr set to a java.util.Set, preserving insertion or sort order.
        Specified by:
        toJavaSet in interface Set<T>
        Specified by:
        toJavaSet in interface Value<T>
        Returns:
        a new java.util.Set instance
      • union

        public HashSet<T> union​(@NonNull Set<? extends T> elements)
        Description copied from interface: Set
        Returns a new set containing all distinct elements from this set and the given set.
        Specified by:
        union in interface Set<T>
        Parameters:
        elements - the set to union with
        Returns:
        a new set with all elements from both sets
      • unzip

        public <T1,​T2> Tuple2<HashSet<T1>,​HashSet<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 Set<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

        public <T1,​T2,​T3> Tuple3<HashSet<T1>,​HashSet<T2>,​HashSet<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 Set<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
      • zip

        public <U> HashSet<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 Set<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

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

        public <U> HashSet<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 Set<T>
        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 HashSet<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 Set<T>
        Specified by:
        zipWithIndex in interface Traversable<T>
        Returns:
        a new Traversable containing each element paired with its index
      • zipWithIndex

        public <U> HashSet<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 Set<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
      • 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
      • 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.
      • toString

        public java.lang.String toString()
        Description copied from interface: Value
        Clarifies that values have a proper toString() method implemented.

        See Object.toString().

        Specified by:
        toString in interface Value<T>
        Overrides:
        toString in class java.lang.Object
        Returns:
        A String representation of this object
      • writeReplace

        @GwtIncompatible("The Java serialization protocol is explicitly not supported")
        private java.lang.Object writeReplace()
        writeReplace method for the serialization proxy pattern.

        The presence of this method causes the serialization system to emit a SerializationProxy instance instead of an instance of the enclosing class.

        Returns:
        A SerializationProxy for this enclosing class.
      • readObject

        @GwtIncompatible("The Java serialization protocol is explicitly not supported")
        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.InvalidObjectException
        readObject method for the serialization proxy pattern.

        Guarantees that the serialization system will never generate a serialized instance of the enclosing class.

        Parameters:
        stream - An object serialization stream.
        Throws:
        java.io.InvalidObjectException - This method will throw with the message "Proxy required".