T
- Component typepublic interface Set<T> extends Traversable<T>, Function1<T,Boolean>
Set
interface.λ.Memoized
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Modifier and Type | Method and Description |
---|---|
Set<T> |
add(T element)
Add the given element to this set, if it is not already contained.
|
Set<T> |
addAll(Iterable<? extends T> elements)
Adds all of the given elements to this set, if not already contained.
|
default Boolean |
apply(T element)
Tests if a given
element is contained in this Set . |
boolean |
contains(T element)
Shortcut for
exists(e -> Objects.equals(e, element)) , tests if the given element is contained. |
Set<T> |
diff(Set<? extends T> that)
Calculates the difference between this set and another set.
|
Set<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
Set<T> |
distinctBy(Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Set<T> |
distinctBy(Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Set<T> |
drop(long n)
Drops the first n elements of this or all elements, if this length < n.
|
Set<T> |
dropRight(long n)
Drops the last n elements of this or all elements, if this length < n.
|
Set<T> |
dropUntil(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
Set<T> |
dropWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
Set<T> |
filter(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
<U> Set<U> |
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
<C> Map<C,? extends Set<T>> |
groupBy(Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Set<T>> |
grouped(long size)
Groups this
Traversable into fixed size blocks. |
Set<T> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<? extends Set<T>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
Set<T> |
intersect(Set<? extends T> that)
Computes the intersection between this set and another set.
|
Iterator<T> |
iterator()
An iterator by means of head() and tail().
|
int |
length()
Computes the number of elements of this Traversable.
|
<U> Set<U> |
map(Function<? super T,? extends U> mapper)
Maps the elements of this
Traversable to elements of a new type preserving their order, if any. |
static <T> Set<T> |
narrow(Set<? extends T> set)
Narrows a widened
Set<? extends T> to Set<T>
by performing a type safe-cast. |
Tuple2<? extends Set<T>,? extends Set<T>> |
partition(Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct tarversables
according to a predicate. |
Set<T> |
peek(Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
Set<T> |
remove(T element)
Removes a specific element from this set, if present.
|
Set<T> |
removeAll(Iterable<? extends T> elements)
Removes all of the given elements from this set, if present.
|
Set<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
Set<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Set<T> |
retainAll(Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
Set<T> |
scan(T zero,
BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> Set<U> |
scanLeft(U zero,
BiFunction<? super U,? super T,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
<U> Set<U> |
scanRight(U zero,
BiFunction<? super T,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
Iterator<? extends Set<T>> |
sliding(long size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(long, long) . |
Iterator<? extends Set<T>> |
sliding(long size,
long step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends Set<T>,? extends Set<T>> |
span(Predicate<? super T> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
default Spliterator<T> |
spliterator() |
Set<T> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends Set<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
Set<T> |
take(long n)
Takes the first n elements of this or all elements, if this length < n.
|
Set<T> |
takeRight(long n)
Takes the last n elements of this or all elements, if this length < n.
|
Set<T> |
takeUntil(Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
Set<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
Set<T> |
toJavaSet()
Converts this Javaslang
Set to a java.util.Set while preserving characteristics
like insertion order (LinkedHashSet ) and sort order (SortedSet ). |
Set<T> |
union(Set<? extends T> that)
Adds all of the elements of
that set to this set, if not already present. |
<T1,T2> Tuple2<? extends Set<T1>,? extends Set<T2>> |
unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
<T1,T2,T3> Tuple3<? extends Set<T1>,? extends Set<T2>,? extends Set<T3>> |
unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
<U> Set<Tuple2<T,U>> |
zip(Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> Set<Tuple2<T,U>> |
zipAll(Iterable<? extends U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
Set<Tuple2<T,Long>> |
zipWithIndex()
Zips this traversable with its indices.
|
average, containsAll, count, existsUnique, find, findLast, foldLeft, foldRight, get, hasDefiniteSize, hash, head, headOption, isEmpty, isSingleValued, isTraversableAgain, last, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, size, sum
fold, reduce, reduceOption
corresponds, eq, equals, exists, forAll, forEach, getOption, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, hashCode, narrow, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaOptional, toJavaSet, toJavaStream, toLeft, toLeft, toList, toMap, toOption, toQueue, toRight, toRight, toSet, toStack, toStream, toString, toTree, toTry, toTry, toVector
andThen, arity, compose, curried, identity, lift, memoized, of, reversed, tupled
isMemoized
static final long serialVersionUID
static <T> Set<T> narrow(Set<? extends T> set)
Set<? extends T>
to Set<T>
by performing a type safe-cast. This is eligible because immutable/read-only
collections are covariant.T
- Component type of the Set
.set
- A Set
.set
instance as narrowed type Set<T>
.Set<T> add(T element)
element
- The element to be added.element
.Set<T> addAll(Iterable<? extends T> elements)
elements
- The elements to be added.elements
, if not already contained.Set<T> diff(Set<? extends T> that)
See also removeAll(Iterable)
.
that
- Elements to be removed from this set.that
set.Set<T> intersect(Set<? extends T> that)
See also retainAll(Iterable)
.
that
- the set to intersect with.that
.Set<T> remove(T element)
element
- The element to be removed from this set.element
.Set<T> removeAll(Iterable<? extends T> elements)
elements
- The elements to be removed from this set.elements
.Set<T> toJavaSet()
Set
to a java.util.Set
while preserving characteristics
like insertion order (LinkedHashSet
) and sort order (SortedSet
).Set<T> union(Set<? extends T> that)
that
set to this set, if not already present.
See also addAll(Iterable)
.
that
- The set to form the union with.that
set.boolean contains(T element)
Value
exists(e -> Objects.equals(e, element))
, tests if the given element
is contained.Set<T> distinct()
Traversable
equals
.distinct
in interface Traversable<T>
Traversable
containing this elements without duplicatesSet<T> distinctBy(Comparator<? super T> comparator)
Traversable
comparator
.distinctBy
in interface Traversable<T>
comparator
- A comparatorTraversable
containing this elements without duplicates<U> Set<T> distinctBy(Function<? super T,? extends U> keyExtractor)
Traversable
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy
in interface Traversable<T>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesSet<T> drop(long n)
Traversable
drop
in interface Traversable<T>
n
- The number of elements to drop.Set<T> dropRight(long n)
Traversable
dropRight
in interface Traversable<T>
n
- The number of elements to drop.Set<T> dropUntil(Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
dropUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.Set<T> dropWhile(Predicate<? super T> predicate)
Traversable
dropWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements starting with the first.Set<T> filter(Predicate<? super T> predicate)
Traversable
filter
in interface Traversable<T>
predicate
- A predicate<U> Set<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
Traversable
flatMap
in interface Traversable<T>
U
- The resulting component type.mapper
- A mapper<C> Map<C,? extends Set<T>> groupBy(Function<? super T,? extends C> classifier)
Traversable
groupBy
in interface Traversable<T>
C
- classified class typeclassifier
- A function which classifies elements into classesIterator<? extends Set<T>> grouped(long size)
Traversable
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].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]]
Please note that grouped(int)
is a special case of Traversable.sliding(long, long), i.e.
grouped(size)
is the same as sliding(size, size)
.grouped
in interface Traversable<T>
size
- a positive block sizeSet<T> init()
Traversable
init
in interface Traversable<T>
Option<? extends Set<T>> initOption()
Traversable
Option
.initOption
in interface Traversable<T>
Some(traversable)
or None
if this is empty.Iterator<T> iterator()
Traversable
int length()
Traversable
Same as Traversable.size()
.
length
in interface Traversable<T>
<U> Set<U> map(Function<? super T,? extends U> mapper)
Traversable
Traversable
to elements of a new type preserving their order, if any.Tuple2<? extends Set<T>,? extends Set<T>> partition(Predicate<? super T> predicate)
Traversable
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.partition
in interface Traversable<T>
predicate
- A predicate which classifies an element if it is in the first or the second traversable.Traversable
contains all elements that satisfy the given predicate
, the second Traversable
contains all elements that don't. The original order of elements is preserved.Set<T> peek(Consumer<? super T> action)
Value
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.Set<T> replace(T currentElement, T newElement)
Traversable
replace
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Set<T> replaceAll(T currentElement, T newElement)
Traversable
replaceAll
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Set<T> retainAll(Iterable<? extends T> elements)
Traversable
retainAll
in interface Traversable<T>
elements
- Elements to be kept.Set<T> scan(T zero, BiFunction<? super T,? super T,? extends T> operation)
Traversable
scan
in interface Traversable<T>
zero
- neutral element for the operator opoperation
- the associative operator for the scan<U> Set<U> scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
Traversable
scanLeft
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the element<U> Set<U> scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
Traversable
scanRight
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementIterator<? extends Set<T>> sliding(long size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(long, long)
.sliding
in interface Traversable<T>
size
- a positive window sizeIterator<? extends Set<T>> sliding(long size, long step)
Traversable
size
and step
size 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]]
sliding
in interface Traversable<T>
size
- a positive window sizestep
- a positive step sizeTuple2<? extends Set<T>,? extends Set<T>> span(Predicate<? super T> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Traversable<T>
predicate
- A predicate.default Spliterator<T> spliterator()
spliterator
in interface Iterable<T>
Set<T> tail()
Traversable
tail
in interface Traversable<T>
Option<? extends Set<T>> tailOption()
Traversable
Option
.tailOption
in interface Traversable<T>
Some(traversable)
or None
if this is empty.Set<T> take(long n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n)))
but does not throw if n < 0
or
n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
take
in interface Traversable<T>
n
- The number of elements to take.Set<T> takeRight(long n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not
throw if n < 0
or n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
takeRight
in interface Traversable<T>
n
- The number of elements to take.Set<T> takeUntil(Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
takeUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.Set<T> takeWhile(Predicate<? super T> predicate)
Traversable
takeWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for the contained elements.<T1,T2> Tuple2<? extends Set<T1>,? extends Set<T2>> unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Traversable
unzip
in interface Traversable<T>
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipperunzipper
- a function which converts elements of this to pairs<T1,T2,T3> Tuple3<? extends Set<T1>,? extends Set<T2>,? extends Set<T3>> unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversable
unzip3
in interface Traversable<T>
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipperunzipper
- a function which converts elements of this to pairs<U> Set<Tuple2<T,U>> zip(Iterable<? extends U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.<U> Set<Tuple2<T,U>> zipAll(Iterable<? extends U> that, T thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.Set<Tuple2<T,Long>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<T>
Copyright © 2016. All Rights Reserved.