Class List.Cons<T>
- java.lang.Object
-
- io.vavr.collection.List.Cons<T>
-
- Type Parameters:
T- Component type of the List.
- All Implemented Interfaces:
Foldable<T>,LinearSeq<T>,List<T>,Seq<T>,Traversable<T>,Function1<java.lang.Integer,T>,PartialFunction<java.lang.Integer,T>,Value<T>,java.io.Serializable,java.lang.Iterable<T>,java.util.function.Function<java.lang.Integer,T>
public static final class List.Cons<T> extends java.lang.Object implements List<T>, java.io.Serializable
Non-emptyList, consisting of aheadand atail.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classList.Cons.SerializationProxy<T>A serialization proxy which, in this context, is used to deserialize immutable, linked Lists with final instance fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.inthashCode()Returns the hash code of this collection.Thead()Returns the first element of this non-emptyTraversable.booleanisEmpty()Checks if this Traversable contains no elements.intlength()Returns the number of elements in this Traversable.private voidreadObject(java.io.ObjectInputStream stream)readObjectmethod for the serialization proxy pattern.List<T>tail()Returns a newTraversablewithout its first element.java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.private java.lang.ObjectwriteReplace()writeReplacemethod for the serialization proxy pattern.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.LinearSeq
asPartialFunction, indexOfSlice, indexWhere, isDefinedAt, lastIndexOfSlice, lastIndexWhere, reverseIterator, search, search, segmentLength
-
Methods inherited from interface io.vavr.collection.List
append, appendAll, asJava, asJava, asJavaMutable, asJavaMutable, collect, combinations, combinations, crossProduct, distinct, distinctBy, distinctBy, distinctByKeepLast, distinctByKeepLast, drop, dropRight, dropRightUntil, dropRightWhile, dropUntil, dropWhile, filter, flatMap, get, groupBy, grouped, hasDefiniteSize, indexOf, init, initOption, insert, insertAll, intersperse, isAsync, isLazy, isTraversableAgain, last, lastIndexOf, leftPadTo, map, mapTo, mapToVoid, orElse, orElse, padTo, partition, patch, peek, peek, peekOption, permutations, pop, pop2, pop2Option, popOption, prepend, prependAll, push, push, pushAll, 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, tailOption, take, takeRight, takeRightUntil, takeRightWhile, takeUntil, takeWhile, transform, unzip, unzip3, update, update, zip, zipAll, zipWith, zipWithIndex, zipWithIndex
-
Methods inherited from interface io.vavr.collection.Seq
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, prefixLength, startsWith, startsWith, withDefault, withDefaultValue
-
Methods inherited from interface io.vavr.collection.Traversable
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, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
head
private final T head
-
length
private final int length
-
-
Method Detail
-
head
public T head()
Description copied from interface:TraversableReturns the first element of this non-emptyTraversable.- Specified by:
headin interfaceTraversable<T>- Returns:
- the first element
-
length
public int length()
Description copied from interface:TraversableReturns the number of elements in this Traversable.Equivalent to
Traversable.size().
-
tail
public List<T> tail()
Description copied from interface:TraversableReturns a newTraversablewithout its first element.
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableChecks if this Traversable contains no elements.
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; }
-
toString
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
writeReplace
@GwtIncompatible("The Java serialization protocol is explicitly not supported") private java.lang.Object writeReplace()
writeReplacemethod for the serialization proxy pattern.The presence of this method causes the serialization system to emit a SerializationProxy instance instead of an instance of the enclosing class.
- Returns:
- A SerializationProxy for this enclosing class.
-
readObject
@GwtIncompatible("The Java serialization protocol is explicitly not supported") private void readObject(java.io.ObjectInputStream stream) throws java.io.InvalidObjectException
readObjectmethod for the serialization proxy pattern.Guarantees that the serialization system will never generate a serialized instance of the enclosing class.
- Parameters:
stream- An object serialization stream.- Throws:
java.io.InvalidObjectException- This method will throw with the message "Proxy required".
-
-