Set interface.Caution
The Vavr Set implementations generally support null elements. However SortedSet
implementations require an element Comparator, which may not support null elements.
Examples:
Set<?> addNull(Set<?> set) {
// CAUTION: Do not expect a Set to accept null values in general!
return set.add(null);
}
void test() {
// ok
addNull(HashSet.of(1));
// ok
addNull(TreeSet.of(nullsFirst(naturalOrder()), 1));
// ok
addNull(TreeSet.empty());
// throws NPE!
addNull(TreeSet.of(1));
}
Basic operations:
Conversion:| Modifier and Type | Field and Description |
|---|---|
| public static final long |
| Modifier and Type | Method and Description |
|---|---|
| public Set | Returns: A new set containing all elements of this set and alsoelement.The element to be added. element)Add the given element to this set, if it is not already contained. |
| public Set | |
| public default Boolean | Returns: true if the given element is contained, false otherwise.the element to test for membership. element)Implements io.
Deprecated
Will be removed
Tests if a given |
| public <R> Set | collect(PartialFunction<? super T, ? extends R>
A function that is not necessarily defined of all elements of this traversable. partialFunction)Redeclares io. Collects all elements that are in the domain of the given |
| public boolean | contains(T
An Object of type A, may be null. element)Redeclares as abstract: io. Shortcut for |
| public Set | |
| public Set | distinct()
Redeclares io. Returns a new version of this which contains no duplicates. |
| public Set | distinctBy(Comparator<? super T>
A comparator comparator)Redeclares io. Returns a new version of this which contains no duplicates. |
| public <U> Set | distinctBy(Function<? super T, ? extends U>
A key extractor keyExtractor)Redeclares io. Returns a new version of this which contains no duplicates. |
| public Set | drop(int
The number of elements to drop. n)Redeclares io. Drops the first n elements of this or all elements, if this length < n. |
| public Set | dropRight(int
The number of elements to drop. n)Redeclares io. Drops the last n elements of this or all elements, if this length < n. |
| public Set | dropUntil(Predicate<? super T>
A condition tested subsequently for this elements. predicate)Redeclares io. Drops elements until the predicate holds for the current element. |
| public Set | dropWhile(Predicate<? super T>
A condition tested subsequently for this elements. predicate)Redeclares io. Drops elements while the predicate holds for the current element. |
| public Set | filter(Predicate<? super T>
A predicate predicate)Redeclares io. Returns a new traversable consisting of all elements which satisfy the given predicate. |
| public <U> Set | flatMap(Function<? super T, ? extends Iterable<? extends U>>
A mapper mapper)Redeclares io. FlatMaps this Traversable. |
| public <C> Map | groupBy(Function<? super T, ? extends C>
A function which classifies elements into classes classifier)Redeclares io. Groups this elements by classifying the elements. |
| public Iterator | grouped(int
a positive block size size)Redeclares io. Groups this |
| public Set | init()
Redeclares io. Dual of tail(), returning all elements except the last. |
| public Option | initOption()
Redeclares as abstract: io. Dual of tailOption(), returning all elements except the last as |
| public Set | |
| public default boolean | isDistinct()
Overrides default io. Checks if this Traversable may consist of distinct elements only. |
| public Iterator | iterator()
Redeclares as abstract: io. An iterator by means of head() and tail(). |
| public int | length()
Redeclares io. Computes the number of elements of this Traversable. |
| public <U> Set | map(Function<? super T, ? extends U>
A mapper. mapper)Redeclares io. Maps the elements of this |
| public static < Component type of the T> SetSet. | |
| public Set | orElse(Iterable<? extends T>
An alternative other)TraversableRedeclares io. Returns this |
| public Set | orElse(Supplier<? extends Iterable<? extends T>>
An alternative supplier)Traversable supplierRedeclares io. Returns this |
| public Tuple2 | partition(Predicate<? super T>
A predicate which classifies an element if it is in the first or the second traversable. predicate)Redeclares io. Creates a partition of this |
| public Set | peek(Consumer<? super T>
The action that will be performed on the element(s). action)Redeclares io. Performs the given |
| public Set | reject(Predicate<? super T>
A predicate predicate)Redeclares as abstract: io. Returns a new traversable consisting of all elements which do not satisfy the given predicate. |
| public Set | Returns: A new set consisting of the elements of this set, without the givenelement.The element to be removed from this set. element)Removes a specific element from this set, if present. |
| public Set | |
| public Set | replace(T
An element to be substituted. currentElement, T A replacement for currentElement. newElement)Redeclares io. Replaces the first occurrence (if exists) of the given currentElement with newElement. |
| public Set | replaceAll(T
An element to be substituted. currentElement, T A replacement for currentElement. newElement)Redeclares io. Replaces all occurrences of the given currentElement with newElement. |
| public Set | retainAll(Iterable<? extends T>
Elements to be kept. elements)Redeclares io. Keeps all occurrences of the given elements from this. |
| public Set | scan(T
neutral element for the operator op zero, BiFunction<? super T, ? super T, ? extends T> the associative operator for the scan operation)Redeclares io. Computes a prefix scan of the elements of the collection. |
| public <U> Set | scanLeft(U
the initial value zero, BiFunction<? super U, ? super T, ? extends U> the binary operator applied to the intermediate result and the element operation)Redeclares io. Produces a collection containing cumulative results of applying the operator going left to right. |
| public <U> Set | scanRight(U
the initial value zero, BiFunction<? super T, ? super U, ? extends U> the binary operator applied to the intermediate result and the element operation)Redeclares io. Produces a collection containing cumulative results of applying the operator going right to left. |
| public Iterator | slideBy(Function<? super T, ?>
A function which classifies elements into classes classifier)Redeclares io. Slides a non-overlapping window of a variable size over this |
| public Iterator | sliding(int
a positive window size size)Redeclares io. Slides a window of a specific |
| public Iterator | sliding(int
a positive window size size, int a positive step size step)Redeclares io. Slides a window of a specific |
| public Tuple2 | span(Predicate<? super T>
A predicate. predicate)Redeclares io. Returns a tuple where the first element is the longest prefix of elements that satisfy the given
|
| public Set | tail()
Redeclares io. Drops the first element of a non-empty Traversable. |
| public Option | tailOption()
Redeclares io. Drops the first element of a non-empty Traversable and returns an |
| public Set | take(int
The number of elements to take. n)Redeclares io. Takes the first n elements of this or all elements, if this length < n. |
| public Set | takeRight(int
The number of elements to take. n)Redeclares io. Takes the last n elements of this or all elements, if this length < n. |
| public Set | takeUntil(Predicate<? super T>
A condition tested subsequently for this elements. predicate)Redeclares io. Takes elements until the predicate holds for the current element. |
| public Set | takeWhile(Predicate<? super T>
A condition tested subsequently for the contained elements. predicate)Redeclares io. Takes elements while the predicate holds for the current element. |
| public Set | Returns: a newjava.util.Set instanceRedeclares as abstract: io. Converts this Vavr |
| public Set | |
| public <T1, T2> Tuple2 | unzip(Function<? super T, Tuple2<? extends T1, ? extends T2>>
a function which converts elements of this to pairs unzipper)Redeclares io. Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct sets. |
| public <T1, T2, T3> Tuple3 | unzip3(Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>>
a function which converts elements of this to pairs unzipper)Redeclares io. Unzips this elements by mapping this elements to triples which are subsequently split into three distinct sets. |
| public <U> Set | zip(Iterable<? extends U>
The Iterable providing the second half of each result pair. that)Redeclares io. Returns a traversable formed from this traversable and another Iterable collection by combining corresponding elements in pairs. |
| public <U> Set | zipAll(Iterable<? extends U>
The Iterable providing the second half of each result pair. that, T The element to be used to fill up the result if this traversable is shorter than that. thisElem, U The element to be used to fill up the result if that is shorter than this traversable. thatElem)Redeclares io. Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in pairs. |
| public <U, R> Set | zipWith(Iterable<? extends U>
The Iterable providing the second parameter of the mapper. that, BiFunction<? super T, ? super U, ? extends R> a mapper. mapper)Redeclares io. Returns a traversable formed from this traversable and another Iterable collection by mapping elements. |
| public Set | zipWithIndex()
Redeclares io. Zips this traversable with its indices. |
| public <U> Set | zipWithIndex(BiFunction<? super T, ? super Integer, ? extends U>
a mapper. mapper)Redeclares io. Zips this traversable with its indices by applying mapper provided. |