T
- Component type of the List.public static final class List.Cons<T> extends Object implements List<T>, Serializable
List
, consisting of a head
and a tail
.Modifier and Type | Method and Description |
---|---|
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.
|
int |
hashCode()
Returns the hash code of this collection.
|
T |
head()
Returns the first element of a non-empty Traversable.
|
boolean |
isEmpty()
Checks if this Traversable is empty.
|
int |
length()
Computes the number of elements of this Traversable.
|
List<T> |
tail()
Drops the first element of a non-empty Traversable.
|
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
append, appendAll, asJava, asJava, asJavaMutable, asJavaMutable, collect, collector, combinations, combinations, crossProduct, distinct, distinctBy, distinctBy, drop, dropRight, dropRightUntil, dropRightWhile, dropUntil, dropWhile, empty, fill, fill, filter, flatMap, get, groupBy, grouped, hasDefiniteSize, indexOf, init, initOption, insert, insertAll, intersperse, isAsync, isLazy, isTraversableAgain, last, lastIndexOf, leftPadTo, map, narrow, of, of, ofAll, ofAll, ofAll, ofAll, ofAll, ofAll, ofAll, ofAll, ofAll, ofAll, orElse, orElse, padTo, partition, patch, peek, peek, peekOption, permutations, pop, pop2, pop2Option, popOption, prepend, prependAll, push, push, pushAll, range, range, range, rangeBy, rangeBy, rangeBy, rangeBy, rangeClosed, rangeClosed, rangeClosed, rangeClosedBy, rangeClosedBy, rangeClosedBy, rangeClosedBy, reject, remove, removeAll, removeAll, removeAll, removeAt, removeFirst, removeLast, replace, replaceAll, retainAll, reverse, rotateLeft, rotateRight, scan, scanLeft, scanRight, shuffle, slice, slideBy, sliding, sliding, sortBy, sortBy, sorted, sorted, span, splitAt, splitAt, splitAtInclusive, stringPrefix, subSequence, subSequence, tabulate, tailOption, take, takeRight, takeRightUntil, takeRightWhile, takeUntil, takeWhile, transform, transpose, unfold, unfoldLeft, unfoldRight, unzip, unzip3, update, update, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
asPartialFunction, indexOfSlice, indexWhere, isDefinedAt, lastIndexOfSlice, lastIndexWhere, narrow, reverseIterator, search, search, segmentLength
apply, containsSlice, crossProduct, crossProduct, endsWith, foldRight, indexOf, indexOfOption, indexOfOption, indexOfSlice, indexOfSliceOption, indexOfSliceOption, indexWhere, indexWhereOption, indexWhereOption, isSequential, iterator, lastIndexOf, lastIndexOfOption, lastIndexOfOption, lastIndexOfSlice, lastIndexOfSliceOption, lastIndexOfSliceOption, lastIndexWhere, lastIndexWhereOption, lastIndexWhereOption, lift, narrow, prefixLength, startsWith, startsWith, withDefault, withDefaultValue
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isDistinct, isOrdered, isSingleValued, iterator, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
fold, reduce, reduceOption
collect, 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, toVector
getIfDefined, unlift
public T head()
Traversable
head
in interface Traversable<T>
public int length()
Traversable
Same as Traversable.size()
.
public List<T> tail()
Traversable
public boolean isEmpty()
Traversable
public boolean equals(Object o)
Traversable
Notes:
public 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()) + ")";
}
}
Copyright © 2020. All Rights Reserved.