T - component type of this Treepublic interface Tree<T> extends Traversable<T>, Serializable
| Modifier and Type | Interface and Description |
|---|---|
static class |
Tree.Empty<T>
The empty tree.
|
static class |
Tree.Node<T>
Represents a tree node.
|
static class |
Tree.Order
Tree traversal order.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
serialVersionUID |
| Modifier and Type | Method and Description |
|---|---|
default int |
branchCount()
Counts the number of branches of this tree.
|
static <T,ID> List<Tree.Node<T>> |
build(Iterable<? extends T> source,
Function<? super T,? extends ID> idMapper,
Function<? super T,? extends ID> parentMapper)
Build a
List with roots of Tree from flat source. |
default <R> Tree<R> |
collect(PartialFunction<? super T,? extends R> partialFunction)
Collects all elements that are in the domain of the given
partialFunction by mapping the elements to type R. |
static <T> Collector<T,ArrayList<T>,Tree<T>> |
collector()
Returns a
Collector which may be used in conjunction with
Stream.collect(java.util.stream.Collector) to obtain a Tree. |
default Seq<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
default Seq<T> |
distinctBy(Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
default <U> Seq<T> |
distinctBy(Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
String |
draw()
Creates a neat 2-dimensional drawing of a tree.
|
default Seq<T> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
default Seq<T> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
default Seq<T> |
dropUntil(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
default Seq<T> |
dropWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
static <T> Tree.Empty<T> |
empty()
Returns the singleton empty tree.
|
boolean |
equals(Object o)
In Vavr there are four basic classes of collections:
Seq (sequential elements)
Set (distinct elements)
Map (indexed elements)
Multimap (indexed collections)
Two collection instances of these classes are equal if and only if both collections
belong to the same basic collection class (Seq, Set, Map or Multimap)
contain the same elements
have the same element order, if the collections are of type Seq
Two Map/Multimap elements, resp.
|
static <T> Tree<T> |
fill(int n,
Supplier<? extends T> s)
Returns a Tree containing
n values supplied by a given Supplier s. |
static <T> Tree<T> |
fill(int n,
T element)
Returns a Tree containing
n times the given element |
default Seq<T> |
filter(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
default <U> Tree<U> |
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
default <U> U |
foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine. |
List<Tree.Node<T>> |
getChildren()
Returns the children of this tree.
|
T |
getValue()
Gets the value of this tree.
|
default <C> Map<C,Seq<T>> |
groupBy(Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
default Iterator<Seq<T>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
default boolean |
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.
|
int |
hashCode()
Returns the hash code of this collection.
|
default T |
head()
Returns the first element of a non-empty Traversable.
|
default Seq<T> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
default Option<Seq<T>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option. |
default boolean |
isAsync()
A
Tree is computed synchronously. |
default boolean |
isBranch()
Checks if this Tree is a branch.
|
default boolean |
isDistinct()
Checks if this Traversable may consist of distinct elements only.
|
default boolean |
isLazy()
A
Tree is computed eagerly. |
boolean |
isLeaf()
Checks if this Tree is a leaf.
|
default boolean |
isSequential()
Checks if the elements of this Traversable appear in encounter order.
|
default boolean |
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.
|
default Iterator<T> |
iterator()
An iterator by means of head() and tail().
|
default Iterator<T> |
iterator(Tree.Order order)
Traverses this tree values in a specific
Tree.Order. |
default int |
leafCount()
Counts the number of leaves of this tree.
|
default <U> Tree<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> Tree<T> |
narrow(Tree<? extends T> tree)
Narrows a widened
Tree<? extends T> to Tree<T>
by performing a type-safe cast. |
default int |
nodeCount()
Counts the number of nodes (i.e.
|
static <T> Tree<T> |
of(T... values)
Creates a Tree of the given elements.
|
static <T> Tree.Node<T> |
of(T value)
Returns a new Node containing the given value and having no children.
|
static <T> Tree.Node<T> |
of(T value,
Iterable<Tree.Node<T>> children)
Returns a new Node containing the given value and having the given children.
|
static <T> Tree.Node<T> |
of(T value,
Tree.Node<T>... children)
Returns a new Node containing the given value and having the given children.
|
static <T> Tree<T> |
ofAll(Iterable<? extends T> iterable)
Creates a Tree of the given elements.
|
static <T> Tree<T> |
ofAll(Stream<? extends T> javaStream)
Creates a Tree that contains the elements of the given
Stream. |
default Tree<T> |
orElse(Iterable<? extends T> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
default Tree<T> |
orElse(Supplier<? extends Iterable<? extends T>> supplier)
Returns this
Traversable if it is nonempty, otherwise return the result of evaluating supplier. |
default Tuple2<Seq<T>,Seq<T>> |
partition(Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
default Tree<T> |
peek(Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
static <T> Tree.Node<T> |
recurse(T seed,
Function<? super T,? extends Iterable<? extends T>> descend)
Recursively builds a non-empty
Tree, starting with the given seed value and proceeding in depth-first order. |
default Seq<T> |
reject(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
default Tree<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
default Tree<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
default Seq<T> |
retainAll(Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
default Seq<T> |
scan(T zero,
BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
default <U> Seq<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.
|
default <U> Seq<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 Iterator<Seq<T>> |
slideBy(Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable. |
default Iterator<Seq<T>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int). |
default Iterator<Seq<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable. |
default Tuple2<Seq<T>,Seq<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 String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
static <T> Tree<T> |
tabulate(int n,
Function<? super Integer,? extends T> f)
Returns a Tree containing
n values of a given Function f
over a range of integer values from 0 to n - 1. |
default Seq<T> |
tail()
Drops the first element of a non-empty Traversable.
|
default Option<Seq<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option. |
default Seq<T> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
default Seq<T> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
default Seq<T> |
takeUntil(Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
default Seq<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
String |
toLispString()
Creates a Lisp-like representation of this
Tree. |
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
default <U> U |
transform(Function<? super Tree<T>,? extends U> f)
Transforms this
Tree. |
default Seq<Tree.Node<T>> |
traverse()
Traverses this tree in
Tree.Order.PRE_ORDER. |
default Seq<Tree.Node<T>> |
traverse(Tree.Order order)
Traverses this tree in a specific order.
|
default <T1,T2> Tuple2<Tree<T1>,Tree<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.
|
default <T1,T2,T3> Tuple3<Tree<T1>,Tree<T2>,Tree<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.
|
default Seq<T> |
values()
Traverses this tree values in
Tree.Order.PRE_ORDER. |
default Seq<T> |
values(Tree.Order order)
Traverses this tree values in a specific order.
|
default <U> Tree<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.
|
default <U> Tree<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.
|
default <U,R> Tree<R> |
zipWith(Iterable<? extends U> that,
BiFunction<? super T,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
default Tree<Tuple2<T,Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
default <U> Tree<U> |
zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isEmpty, isOrdered, isSingleValued, last, lastOption, length, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sumfold, reduce, reduceOptioncollect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, narrow, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVectorstatic final long serialVersionUID
static <T> Collector<T,ArrayList<T>,Tree<T>> collector()
Collector which may be used in conjunction with
Stream.collect(java.util.stream.Collector) to obtain a Tree.T - Component type of the Tree.static <T> Tree.Empty<T> empty()
T - Type of tree values.static <T> Tree<T> narrow(Tree<? extends T> tree)
Tree<? extends T> to Tree<T>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.T - Component type of the Tree.tree - An Tree.tree instance as narrowed type Tree<T>.static <T> Tree.Node<T> of(T value)
T - Value typevalue - A value@SafeVarargs static <T> Tree.Node<T> of(T value, Tree.Node<T>... children)
T - Value typevalue - A valuechildren - The child nodes, possibly emptystatic <T> Tree.Node<T> of(T value, Iterable<Tree.Node<T>> children)
T - Value typevalue - A valuechildren - The child nodes, possibly empty@SafeVarargs static <T> Tree<T> of(T... values)
T - Component type of the List.values - Zero or more values.NullPointerException - if values is nullstatic <T> Tree<T> ofAll(Iterable<? extends T> iterable)
If the given iterable is a tree, it is returned as result. if the iteration order of the elements is stable.
T - Component type of the List.iterable - An Iterable of elements.NullPointerException - if elements is nullstatic <T> Tree<T> ofAll(Stream<? extends T> javaStream)
Stream.T - Component type of the Stream.javaStream - A Streamstatic <T> Tree<T> tabulate(int n, Function<? super Integer,? extends T> f)
n values of a given Function f
over a range of integer values from 0 to n - 1.T - Component type of the Treen - The number of elements in the Treef - The Function computing element valuesf(0),f(1), ..., f(n - 1)NullPointerException - if f is nullstatic <T> Tree<T> fill(int n, Supplier<? extends T> s)
n values supplied by a given Supplier s.T - Component type of the Treen - The number of elements in the Trees - The Supplier computing element valuesn, where each element contains the result supplied by s.NullPointerException - if s is nullstatic <T> Tree<T> fill(int n, T element)
n times the given elementT - Component type of the Treen - The number of elements in the Treeelement - The elementn, where each element is the given element.static <T> Tree.Node<T> recurse(T seed, Function<? super T,? extends Iterable<? extends T>> descend)
Tree, starting with the given seed value and proceeding in depth-first order.
The children of a node are created by
descend function to the node valueExample:
// = (1 (2 4 5) 3)
Tree.recurse(1, i ->
(i == 1) ? List.of(2, 3) :
(i == 2) ? List.(4, 5) :
List.empty()
).toLispString();
T - Value typeseed - The start value for the Treedescend - A function to calculate the child valuesTree instanceNullPointerException - if descend is nullstatic <T,ID> List<Tree.Node<T>> build(Iterable<? extends T> source, Function<? super T,? extends ID> idMapper, Function<? super T,? extends ID> parentMapper)
List with roots of Tree from flat source.
parentMapper must return null for root element.
// = [(1, null, "I"), (2, 1, "II"), (3, 1, "III"), (4, 2, "IV"), (5, 2, "V")]
List<MenuItem> items = ...; // MenuItem(id, parentId, label)
// I
// / \
// II III
// /\
// IV V
Tree<MenuItem> menu = Tree.build(items, MenuItem::getId, MenuItem::getParentId);
T - Value typeID - Id typesource - Flat sourceidMapper - A mapper from source item to unique identifier of that itemparentMapper - A mapper from source item to unique identifier of parent item. Need return null for root itemsList instance with non-empty Tree instancesNullPointerException - if source, idMapper or parentMapper is nulldefault <R> Tree<R> collect(PartialFunction<? super T,? extends R> partialFunction)
TraversablepartialFunction by mapping the elements to type R.
More specifically, for each of this elements in iteration order first it is checked
partialFunction.isDefinedAt(element)
If the elements makes it through that filter, the mapped instance is added to the result collection
R newElement = partialFunction.apply(element)
Note:If this Traversable is ordered (i.e. extends Ordered,
the caller of collect has to ensure that the elements are comparable (i.e. extend Comparable).collect in interface Traversable<T>R - The new element typepartialFunction - A function that is not necessarily defined of all elements of this traversable.Traversable instance containing elements of type RT getValue()
UnsupportedOperationException - if this tree is emptyList<Tree.Node<T>> getChildren()
boolean isLeaf()
default boolean isBranch()
default boolean isAsync()
Tree is computed synchronously.default boolean isDistinct()
TraversableisDistinct in interface Traversable<T>default boolean isLazy()
Tree is computed eagerly.default boolean isSequential()
TraversableisSequential in interface Traversable<T>default Iterator<T> iterator(Tree.Order order)
Tree.Order.order - A traversal orderString toLispString()
Tree.Tree as Lisp-string, i.e. represented as list of lists.default <U> U transform(Function<? super Tree<T>,? extends U> f)
Tree.U - Type of transformation resultf - A transformationUNullPointerException - if f is nulldefault Seq<Tree.Node<T>> traverse()
Tree.Order.PRE_ORDER.default Seq<Tree.Node<T>> traverse(Tree.Order order)
order - the tree traversal orderNullPointerException - if order is nulldefault Seq<T> values()
Tree.Order.PRE_ORDER.
Syntactic sugar for traverse().map(Node::getValue).default Seq<T> values(Tree.Order order)
traverse(order).map(Node::getValue).order - the tree traversal orderNullPointerException - if order is nulldefault int branchCount()
default int leafCount()
default int nodeCount()
default Seq<T> distinct()
Traversableequals.distinct in interface Traversable<T>Traversable containing this elements without duplicatesdefault Seq<T> distinctBy(Comparator<? super T> comparator)
Traversablecomparator.distinctBy in interface Traversable<T>comparator - A comparatorTraversable containing this elements without duplicatesdefault <U> Seq<T> distinctBy(Function<? super T,? extends U> keyExtractor)
Traversableequals.
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 duplicatesdefault Seq<T> drop(int n)
Traversabledrop in interface Traversable<T>n - The number of elements to drop.default Seq<T> dropRight(int n)
TraversabledropRight in interface Traversable<T>n - The number of elements to drop.default Seq<T> dropUntil(Predicate<? super T> predicate)
TraversabledropUntil in interface Traversable<T>predicate - A condition tested subsequently for this elements.default Seq<T> dropWhile(Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropUntil(predicate.negate()).
It is intended to be used with method references, which cannot be negated directly.
dropWhile in interface Traversable<T>predicate - A condition tested subsequently for this elements.default Seq<T> filter(Predicate<? super T> predicate)
Traversablefilter in interface Traversable<T>predicate - A predicatedefault Seq<T> reject(Predicate<? super T> predicate)
TraversableThe default implementation is equivalent to
filter(predicate.negate()reject in interface Traversable<T>predicate - A predicatedefault <U> Tree<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
TraversableflatMap in interface Traversable<T>U - The resulting component type.mapper - A mapperdefault <U> U foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Foldablezero and successively calling combine.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
default <C> Map<C,Seq<T>> groupBy(Function<? super T,? extends C> classifier)
TraversablegroupBy in interface Traversable<T>C - classified class typeclassifier - A function which classifies elements into classesTraversable.arrangeBy(Function)default Iterator<Seq<T>> grouped(int size)
TraversableTraversable 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(int, int), i.e.
grouped(size) is the same as sliding(size, size).grouped in interface Traversable<T>size - a positive block sizedefault boolean hasDefiniteSize()
TraversableThis method should be implemented by classes only, i.e. not by interfaces.
hasDefiniteSize in interface Traversable<T>default T head()
Traversablehead in interface Traversable<T>default Seq<T> init()
Traversableinit in interface Traversable<T>default Option<Seq<T>> initOption()
TraversableOption.initOption in interface Traversable<T>Some(traversable) or None if this is empty.default boolean isTraversableAgain()
TraversableThis method should be implemented by classes only, i.e. not by interfaces.
isTraversableAgain in interface Traversable<T>default Iterator<T> iterator()
Traversabledefault <U> Tree<U> map(Function<? super T,? extends U> mapper)
TraversableTraversable to elements of a new type preserving their order, if any.default Tree<T> orElse(Iterable<? extends T> other)
TraversableTraversable if it is nonempty, otherwise return the alternative.orElse in interface Traversable<T>other - An alternative TraversableTraversable if it is nonempty, otherwise return the alternative.default Tree<T> orElse(Supplier<? extends Iterable<? extends T>> supplier)
TraversableTraversable if it is nonempty, otherwise return the result of evaluating supplier.orElse in interface Traversable<T>supplier - An alternative Traversable supplierTraversable if it is nonempty, otherwise return the result of evaluating supplier.default Tuple2<Seq<T>,Seq<T>> partition(Predicate<? super T> predicate)
TraversableTraversable by splitting this elements in two in distinct traversables
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.default Tree<T> peek(Consumer<? super T> action)
Valueaction 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 Tree<T> replace(T currentElement, T newElement)
Traversablereplace in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.default Tree<T> replaceAll(T currentElement, T newElement)
TraversablereplaceAll in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.default Seq<T> retainAll(Iterable<? extends T> elements)
TraversableretainAll in interface Traversable<T>elements - Elements to be kept.default Seq<T> scan(T zero, BiFunction<? super T,? super T,? extends T> operation)
Traversablescan in interface Traversable<T>zero - neutral element for the operator opoperation - the associative operator for the scandefault <U> Seq<U> scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
TraversablescanLeft 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 elementdefault <U> Seq<U> scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
TraversablescanRight 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 elementdefault Iterator<Seq<T>> slideBy(Function<? super T,?> classifier)
TraversableTraversable.
Each window contains elements with the same class, as determined by classifier. Two consecutive
values in this Traversable will be in the same window only if classifier returns equal
values for them. Otherwise, the values will constitute the last element of the previous window and the
first element of the next window.
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]]
slideBy in interface Traversable<T>classifier - A function which classifies elements into classesdefault Iterator<Seq<T>> sliding(int size)
Traversablesize and step size 1 over this Traversable by calling
Traversable.sliding(int, int).sliding in interface Traversable<T>size - a positive window sizedefault Iterator<Seq<T>> sliding(int size, int step)
Traversablesize 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 sizedefault Tuple2<Seq<T>,Seq<T>> span(Predicate<? super T> predicate)
Traversablepredicate and the second element is the remainder.span in interface Traversable<T>predicate - A predicate.Tuple containing the longest prefix of elements that satisfy p and the remainder.default String stringPrefix()
ValuestringPrefix in interface Value<T>default Seq<T> tail()
Traversabletail in interface Traversable<T>default Option<Seq<T>> tailOption()
TraversableOption.tailOption in interface Traversable<T>Some(traversable) or None if this is empty.default Seq<T> take(int 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.default Seq<T> takeRight(int 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.default Seq<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.default Seq<T> takeWhile(Predicate<? super T> predicate)
TraversabletakeWhile in interface Traversable<T>predicate - A condition tested subsequently for the contained elements.default <T1,T2> Tuple2<Tree<T1>,Tree<T2>> unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Traversableunzip 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 pairsdefault <T1,T2,T3> Tuple3<Tree<T1>,Tree<T2>,Tree<T3>> unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversableunzip3 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 pairsdefault <U> Tree<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.default <U,R> Tree<R> zipWith(Iterable<? extends U> that, BiFunction<? super T,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith in interface Traversable<T>U - The type of the second parameter of the mapper.R - The type of the mapped elements.that - The Iterable providing the second parameter of the mapper.mapper - a mapper.that iterable.default <U> Tree<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.default Tree<Tuple2<T,Integer>> zipWithIndex()
TraversablezipWithIndex in interface Traversable<T>default <U> Tree<U> zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex in interface Traversable<T>U - The type of the mapped elements.mapper - a mapper.that iterable.boolean equals(Object o)
TraversableNotes:
int hashCode()
Traversable
int hash = 1;
for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.
int hash = 1;
for (T t : this) { hash += Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.
public final class Hashed<K> {
private final K key;
private final Lazy<Integer> hashCode;
public Hashed(K key) {
this.key = key;
this.hashCode = Lazy.of(() -> Objects.hashCode(key));
}
public K key() {
return key;
}
@Override
public boolean equals(Object o) {
if (o == key) {
return true;
} else if (key != null && o instanceof Hashed) {
final Hashed that = (Hashed) o;
return key.equals(that.key);
} else {
return false;
}
}
@Override
public int hashCode() {
return hashCode.get();
}
@Override
public String toString() {
return "Hashed(" + (key == null ? "null" : key.toString()) + ")";
}
}String toString()
ValueSee Object.toString().
String draw()
Copyright © 2019. All Rights Reserved.