T
- Component typepublic interface Traversable<T> extends Foldable<T>, Value<T>
Iterable.iterator()
, which may vary each time it is called.
Implementations of Traversable
should calculate the hashCode
via hash(Iterable)
.
Basic operations:
Value.contains(Object)
containsAll(Iterable)
head()
headOption()
init()
initOption()
isEmpty()
last()
lastOption()
length()
size()
tail()
tailOption()
average()
max()
maxBy(Comparator)
maxBy(Function)
min()
minBy(Comparator)
minBy(Function)
product()
sum()
count(Predicate)
Foldable.fold(Object, BiFunction)
foldLeft(Object, BiFunction)
foldRight(Object, BiFunction)
mkString()
mkString(CharSequence)
mkString(CharSequence, CharSequence, CharSequence)
Foldable.reduce(BiFunction)
Foldable.reduceOption(BiFunction)
reduceLeft(BiFunction)
reduceLeftOption(BiFunction)
reduceRight(BiFunction)
reduceRightOption(BiFunction)
drop(long)
dropRight(long)
dropUntil(Predicate)
dropWhile(Predicate)
filter(Predicate)
find(Predicate)
findLast(Predicate)
groupBy(Function)
partition(Predicate)
retainAll(Iterable)
take(long)
takeRight(long)
takeUntil(Predicate)
takeWhile(Predicate)
distinct()
distinctBy(Comparator)
distinctBy(Function)
flatMap(Function)
map(Function)
replace(Object, Object)
replaceAll(Object, Object)
scan(Object, BiFunction)
scanLeft(Object, BiFunction)
scanRight(Object, BiFunction)
span(Predicate)
unzip(Function)
unzip3(Function)
zip(Iterable)
zipAll(Iterable, Object, Object)
zipWithIndex()
Modifier and Type | Method and Description |
---|---|
default Option<Double> |
average()
Calculates the average of this elements.
|
default boolean |
containsAll(Iterable<? extends T> elements)
Tests if this Traversable contains all given elements.
|
default int |
count(Predicate<? super T> predicate)
Counts the elements which satisfy the given predicate.
|
Traversable<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
Traversable<T> |
distinctBy(Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Traversable<T> |
distinctBy(Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Traversable<T> |
drop(long n)
Drops the first n elements of this or all elements, if this length < n.
|
Traversable<T> |
dropRight(long n)
Drops the last n elements of this or all elements, if this length < n.
|
Traversable<T> |
dropUntil(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
Traversable<T> |
dropWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
default boolean |
existsUnique(Predicate<? super T> predicate)
Checks, if a unique elements exists such that the predicate holds.
|
Traversable<T> |
filter(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
default Option<T> |
find(Predicate<? super T> predicate)
Returns the first element of this which satisfies the given predicate.
|
default Option<T> |
findLast(Predicate<? super T> predicate)
Returns the last element of this which satisfies the given predicate.
|
<U> Traversable<U> |
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
default <U> U |
foldLeft(U zero,
BiFunction<? super U,? super T,? extends U> f)
Accumulates the elements of this Traversable by successively calling the given function
f from the left,
starting with a value zero of type B. |
<U> U |
foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Accumulates the elements of this Traversable by successively calling the given function
f from the right,
starting with a value zero of type B. |
default T |
get()
Gets the underlying value or throws if no value is present.
|
<C> Map<C,? extends Traversable<T>> |
groupBy(Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Traversable<T>> |
grouped(long size)
Groups this
Traversable into fixed size blocks. |
boolean |
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.
|
static <T> int |
hash(Iterable<? extends T> objects)
Used by collections to compute the hashCode only once.
|
T |
head()
Returns the first element of a non-empty Traversable.
|
Option<T> |
headOption()
Returns the first element of a non-empty Traversable as
Option . |
Traversable<T> |
init()
Dual of tail(), returning all elements except the last.
|
Option<? extends Traversable<T>> |
initOption()
Dual of tailOption(), returning all elements except the last as
Option . |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
default boolean |
isSingleValued()
Each of Javaslang's collections may contain more than one element.
|
boolean |
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.
|
default Iterator<T> |
iterator()
An iterator by means of head() and tail().
|
default T |
last()
Dual of head(), returning the last element.
|
default Option<T> |
lastOption()
Dual of headOption(), returning the last element as
Opiton . |
int |
length()
Computes the number of elements of this Traversable.
|
<U> Traversable<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. |
default Option<T> |
max()
Calculates the maximum of this elements according to their natural order.
|
default Option<T> |
maxBy(Comparator<? super T> comparator)
Calculates the maximum of this elements using a specific comparator.
|
default <U extends Comparable<? super U>> |
maxBy(Function<? super T,? extends U> f)
Calculates the maximum of this elements within the co-domain of a specific function.
|
default Option<T> |
min()
Calculates the minimum of this elements according to their natural order.
|
default Option<T> |
minBy(Comparator<? super T> comparator)
Calculates the minimum of this elements using a specific comparator.
|
default <U extends Comparable<? super U>> |
minBy(Function<? super T,? extends U> f)
Calculates the minimum of this elements within the co-domain of a specific function.
|
default String |
mkString()
Joins the elements of this by concatenating their string representations.
|
default String |
mkString(CharSequence delimiter)
Joins the string representations of this elements using a specific delimiter.
|
default String |
mkString(CharSequence prefix,
CharSequence delimiter,
CharSequence suffix)
Joins the string representations of this elements using a specific delimiter, prefix and suffix.
|
static <T> Traversable<T> |
narrow(Traversable<? extends T> traversable)
Narrows a widened
Traversable<? extends T> to Traversable<T>
by performing a type safe-cast. |
default boolean |
nonEmpty()
Checks, this
Traversable is not empty. |
Tuple2<? extends Traversable<T>,? extends Traversable<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. |
Traversable<T> |
peek(Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
default Number |
product()
Calculates the product of this elements.
|
default T |
reduceLeft(BiFunction<? super T,? super T,? extends T> op)
Accumulates the elements of this Traversable by successively calling the given operation
op from the left. |
default Option<T> |
reduceLeftOption(BiFunction<? super T,? super T,? extends T> op)
Shortcut for
isEmpty() ? Option.none() : Option.some(reduceLeft(op)) . |
default T |
reduceRight(BiFunction<? super T,? super T,? extends T> op)
Accumulates the elements of this Traversable by successively calling the given operation
op from the right. |
default Option<T> |
reduceRightOption(BiFunction<? super T,? super T,? extends T> op)
Shortcut for
isEmpty() ? Option.none() : Option.some(reduceRight(op)) . |
Traversable<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
Traversable<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Traversable<T> |
retainAll(Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
Traversable<T> |
scan(T zero,
BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> Traversable<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> Traversable<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.
|
default int |
size()
Computes the number of elements of this Traversable.
|
Iterator<? extends Traversable<T>> |
sliding(long size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
sliding(long, long) . |
Iterator<? extends Traversable<T>> |
sliding(long size,
long step)
Slides a window of a specific
size and step size over this Traversable . |
Tuple2<? extends Traversable<T>,? extends Traversable<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 Number |
sum()
Calculates the sum of this elements.
|
Traversable<T> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends Traversable<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
Traversable<T> |
take(long n)
Takes the first n elements of this or all elements, if this length < n.
|
Traversable<T> |
takeRight(long n)
Takes the last n elements of this or all elements, if this length < n.
|
Traversable<T> |
takeUntil(Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
Traversable<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
<T1,T2> Tuple2<? extends Traversable<T1>,? extends Traversable<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 Traversable<T1>,? extends Traversable<T2>,? extends Traversable<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> Traversable<Tuple2<T,U>> |
zip(Iterable<U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> Traversable<Tuple2<T,U>> |
zipAll(Iterable<U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
Traversable<Tuple2<T,Long>> |
zipWithIndex()
Zips this traversable with its indices.
|
fold, reduce, reduceOption
contains, 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, toJavaSet, toJavaStream, toLeft, toLeft, toList, toMap, toOption, toQueue, toRight, toRight, toSet, toStack, toStream, toString, toTree, toTry, toTry, toVector
spliterator
static <T> int hash(Iterable<? extends T> objects)
Idiom:
class MyCollection implements Serializable {
// Not allowed to be serialized!
private final transient Lazy<Integer> hashCode = Lazy.of(() -> Traversable.hash(this));
@Override
public int hashCode() {
return hashCode.get();
}
}
Note: In the case of an empty collection, such as Nil
it is recommended to
directly return Traversable.hash(this)
instead of asking a Lazy
value:
interface List<T> {
class Nil<T> {
@Override
public int hashCode() {
return Traversable.hash(this);
}
}
}
T
- Component typeobjects
- An IterableNullPointerException
- if objects is nullstatic <T> Traversable<T> narrow(Traversable<? extends T> traversable)
Traversable<? extends T>
to Traversable<T>
by performing a type safe-cast. This is eligible because immutable/read-only
collections are covariant.T
- Component type of the Traversable
.traversable
- An Traversable
.traversable
instance as narrowed type Traversable<T>
.default Option<Double> average()
None
if this is empty, otherwise Some(average)
.
Supported component types are Byte
, Double
, Float
, Integer
, Long
,
Short
, BigInteger
and BigDecimal
.
Examples:
List.empty().average() // = None
List.of(1, 2, 3).average() // = Some(2.0)
List.of(0.1, 0.2, 0.3).average() // = Some(0.2)
List.of("apple", "pear").average() // throws
Some(average)
or None
, if there are no elementsUnsupportedOperationException
- if this elements are not numericdefault boolean containsAll(Iterable<? extends T> elements)
The result is equivalent to
elements.isEmpty() ? true : contains(elements.head()) && containsAll(elements.tail())
but implemented
without recursion.
elements
- A List of values of type T.NullPointerException
- if elements
is nulldefault int count(Predicate<? super T> predicate)
predicate
- A predicate>= 0
NullPointerException
- if predicate
is null.Traversable<T> distinct()
equals
.Traversable
containing this elements without duplicatesTraversable<T> distinctBy(Comparator<? super T> comparator)
comparator
.comparator
- A comparatorTraversable
containing this elements without duplicatesNullPointerException
- if comparator
is null.<U> Traversable<T> distinctBy(Function<? super T,? extends U> keyExtractor)
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesNullPointerException
- if keyExtractor
is nullTraversable<T> drop(long n)
n
- The number of elements to drop.Traversable<T> dropRight(long n)
n
- The number of elements to drop.Traversable<T> dropUntil(Predicate<? super T> predicate)
Note: This is essentially the same as dropWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
predicate
- A condition tested subsequently for this elements.NullPointerException
- if predicate
is nullTraversable<T> dropWhile(Predicate<? super T> predicate)
predicate
- A condition tested subsequently for this elements starting with the first.NullPointerException
- if predicate
is nulldefault boolean existsUnique(Predicate<? super T> predicate)
predicate
- A PredicateNullPointerException
- if predicate
is nullTraversable<T> filter(Predicate<? super T> predicate)
predicate
- A predicateNullPointerException
- if predicate
is nulldefault Option<T> find(Predicate<? super T> predicate)
predicate
- A predicate.List.of(null).find(e -> e == null)
).NullPointerException
- if predicate
is nulldefault Option<T> findLast(Predicate<? super T> predicate)
Same as reverse().find(predicate)
.
predicate
- A predicate.List.of(null).find(e -> e == null)
).NullPointerException
- if predicate
is null<U> Traversable<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
U
- The resulting component type.mapper
- A mapperdefault <U> U foldLeft(U zero, BiFunction<? super U,? super T,? extends U> f)
f
from the left,
starting with a value zero
of type B.
Example: Reverse and map a Traversable in one pass
List.of("a", "b", "c").foldLeft(List.empty(), (xs, x) -> xs.prepend(x.toUpperCase()))
// = List("C", "B", "A")
foldLeft
in interface Foldable<T>
U
- Result type of the accumulator.zero
- Value to start the accumulation with.f
- The accumulator function.NullPointerException
- if f
is null<U> U foldRight(U zero, BiFunction<? super T,? super U,? extends U> f)
f
from the right,
starting with a value zero
of type B.
Example: List.of("a", "b", "c").foldRight("", (x, xs) -> x + xs) = "abc"
foldRight
in interface Foldable<T>
U
- Result type of the accumulator.zero
- Value to start the accumulation with.f
- The accumulator function.NullPointerException
- if f
is nulldefault T get()
Value
<C> Map<C,? extends Traversable<T>> groupBy(Function<? super T,? extends C> classifier)
C
- classified class typeclassifier
- A function which classifies elements into classesNullPointerException
- if classifier
is null.Iterator<? extends Traversable<T>> grouped(long size)
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 sliding(long, long), i.e.
grouped(size)
is the same as sliding(size, size)
.size
- a positive block sizeIllegalArgumentException
- if size
is negative or zeroboolean hasDefiniteSize()
This method should be implemented by classes only, i.e. not by interfaces.
T head()
NoSuchElementException
- if this is emptyOption<T> headOption()
Option
.Some(element)
or None
if this is empty.Traversable<T> init()
UnsupportedOperationException
- if this is emptyOption<? extends Traversable<T>> initOption()
Option
.Some(traversable)
or None
if this is empty.boolean isEmpty()
default boolean isSingleValued()
isSingleValued
in interface Value<T>
false
boolean isTraversableAgain()
This method should be implemented by classes only, i.e. not by interfaces.
default Iterator<T> iterator()
default T last()
NoSuchElementException
- is this is emptydefault Option<T> lastOption()
Opiton
.Some(element)
or None
if this is empty.int length()
Same as size()
.
<U> Traversable<U> map(Function<? super T,? extends U> mapper)
Traversable
to elements of a new type preserving their order, if any.map
in interface Value<T>
U
- Component type of the target Traversablemapper
- A mapper.NullPointerException
- if mapper
is nulldefault Option<T> max()
Some(maximum)
of this elements or None
if this is empty or this elements are not comparabledefault Option<T> maxBy(Comparator<? super T> comparator)
comparator
- A non-null element comparatorSome(maximum)
of this elements or None
if this is emptyNullPointerException
- if comparator
is nulldefault <U extends Comparable<? super U>> Option<T> maxBy(Function<? super T,? extends U> f)
U
- The type where elements are comparedf
- A function that maps this elements to comparable elementsNullPointerException
- if f
is null.default Option<T> min()
Some(minimum)
of this elements or None
if this is empty or this elements are not comparabledefault Option<T> minBy(Comparator<? super T> comparator)
comparator
- A non-null element comparatorSome(minimum)
of this elements or None
if this is emptyNullPointerException
- if comparator
is nulldefault <U extends Comparable<? super U>> Option<T> minBy(Function<? super T,? extends U> f)
U
- The type where elements are comparedf
- A function that maps this elements to comparable elementsNullPointerException
- if f
is null.default String mkString()
This has the same effect as calling mkString("", "", "")
.
default String mkString(CharSequence delimiter)
This has the same effect as calling mkString(delimiter, "", "")
.
delimiter
- A delimiter string put between string representations of elements of thisdefault String mkString(CharSequence prefix, CharSequence delimiter, CharSequence suffix)
Example: List.of("a", "b", "c").mkString(", ", "Chars(", ")") = "Chars(a, b, c)"
prefix
- prefix of the resulting stringdelimiter
- A delimiter string put between string representations of elements of thissuffix
- suffix of the resulting stringdefault boolean nonEmpty()
Traversable
is not empty.
The call is equivalent to !isEmpty()
.
Tuple2<? extends Traversable<T>,? extends Traversable<T>> partition(Predicate<? super T> predicate)
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.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.NullPointerException
- if predicate is nullTraversable<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.default Number product()
Byte
, Double
, Float
,
Integer
, Long
, Short
, BigInteger
and BigDecimal
.
Examples:
List.empty().product() // = 1
List.of(1, 2, 3).product() // = 6L
List.of(0.1, 0.2, 0.3).product() // = 0.006
List.of("apple", "pear").product() // throws
Number
representing the sum of this elementsUnsupportedOperationException
- if this elements are not numericdefault T reduceLeft(BiFunction<? super T,? super T,? extends T> op)
op
from the left.reduceLeft
in interface Foldable<T>
op
- A BiFunction of type TNoSuchElementException
- if this is emptyNullPointerException
- if op
is nulldefault Option<T> reduceLeftOption(BiFunction<? super T,? super T,? extends T> op)
isEmpty() ? Option.none() : Option.some(reduceLeft(op))
.reduceLeftOption
in interface Foldable<T>
op
- A BiFunction of type TNullPointerException
- if op
is nulldefault T reduceRight(BiFunction<? super T,? super T,? extends T> op)
op
from the right.reduceRight
in interface Foldable<T>
op
- An operation of type TNoSuchElementException
- if this is emptyNullPointerException
- if op
is nulldefault Option<T> reduceRightOption(BiFunction<? super T,? super T,? extends T> op)
isEmpty() ? Option.none() : Option.some(reduceRight(op))
.reduceRightOption
in interface Foldable<T>
op
- An operation of type TNullPointerException
- if op
is nullTraversable<T> replace(T currentElement, T newElement)
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Traversable<T> replaceAll(T currentElement, T newElement)
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Traversable<T> retainAll(Iterable<? extends T> elements)
elements
- Elements to be kept.NullPointerException
- if elements
is nullTraversable<T> scan(T zero, BiFunction<? super T,? super T,? extends T> operation)
zero
- neutral element for the operator opoperation
- the associative operator for the scanNullPointerException
- if operation
is null.<U> Traversable<U> scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementNullPointerException
- if operation
is null.<U> Traversable<U> scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementNullPointerException
- if operation
is null.default int size()
Same as length()
.
Iterator<? extends Traversable<T>> sliding(long size)
size
and step size 1 over this Traversable
by calling
sliding(long, long)
.size
- a positive window sizeIllegalArgumentException
- if size
is negative or zeroIterator<? extends Traversable<T>> sliding(long size, long step)
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]]
size
- a positive window sizestep
- a positive step sizeIllegalArgumentException
- if size
or step
are negative or zeroTuple2<? extends Traversable<T>,? extends Traversable<T>> span(Predicate<? super T> predicate)
predicate
and the second element is the remainder.predicate
- A predicate.NullPointerException
- if predicate
is nulldefault Number sum()
Byte
, Double
, Float
,
Integer
, Long
, Short
, BigInteger
and BigDecimal
.
Examples:
List.empty().sum() // = 0
List.of(1, 2, 3).sum() // = 6L
List.of(0.1, 0.2, 0.3).sum() // = 0.6
List.of("apple", "pear").sum() // throws
Number
representing the sum of this elementsUnsupportedOperationException
- if this elements are not numericTraversable<T> tail()
UnsupportedOperationException
- if this is emptyOption<? extends Traversable<T>> tailOption()
Option
.Some(traversable)
or None
if this is empty.Traversable<T> take(long n)
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.
n
- The number of elements to take.Traversable<T> takeRight(long n)
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.
n
- The number of elements to take.Traversable<T> takeUntil(Predicate<? super T> predicate)
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
predicate
- A condition tested subsequently for this elements.NullPointerException
- if predicate
is nullTraversable<T> takeWhile(Predicate<? super T> predicate)
predicate
- A condition tested subsequently for the contained elements.NullPointerException
- if predicate
is null<T1,T2> Tuple2<? extends Traversable<T1>,? extends Traversable<T2>> unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
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 pairsNullPointerException
- if unzipper
is null<T1,T2,T3> Tuple3<? extends Traversable<T1>,? extends Traversable<T2>,? extends Traversable<T3>> unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
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 pairsNullPointerException
- if unzipper
is null<U> Traversable<Tuple2<T,U>> zip(Iterable<U> that)
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.NullPointerException
- if that
is null<U> Traversable<Tuple2<T,U>> zipAll(Iterable<U> that, T thisElem, U thatElem)
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.
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.NullPointerException
- if that
is nullTraversable<Tuple2<T,Long>> zipWithIndex()
Copyright © 2016. All Rights Reserved.