Class PList<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Iterable<E>,IntFunction<E>
- Direct Known Subclasses:
PList.Cons,PList.Nil
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionCreate a new list by addingelementto the tail of this list, i.apply(int index) static <A> PList<A>Create a “cons cell”, using the given head and tail.static <A> PList<A>Traverse the iterator to create a new list.A collector that can be used withStream.collect(Collector)to collect a stream into aPList.Concatenates the given list ontothislist.Create a new list by addingelementto the beginning of this list.booleancontains(E element, BiPredicate<E, E> eq) Check whether the given element is a member of this list.distinct(Comparator<E> comparator) Remove duplicate elements.Remove duplicate elements retaining the order.drop(int count) Drop the firstcountelements of this list.dropRight(int count) Return a new list with the lastcountelements removed.duplicates(Comparator<E> comparator) Retain only elements that exists more than once.static <A> PList<A>empty()Returns the empty list.booleanbooleanCheck whether any element in this list holds the predicate.static <A> PList<A>Create a list by calling the given supplierlengthtimes.Return a new list with only those elements ofthisthat holds the given predicate.filterWithNext(BiPredicate<E, E> filter, Predicate<E> last) Filter this list by peeking the next element.filterWithPrev(Predicate<E> first, BiPredicate<E, E> filter) Filter this list by peeking the previous element.Find the first element that holds the given predicate.<B> PList<B>Applyfto each element in the list and concatenate the results.<B> PList<B>flatMapOptional(Function<E, Optional<B>> f) Applyfto each element in the list and concatenate the non-empty results.<B> BfoldLeft(B init, BiFunction<B, E, B> f) Folds the list from the left.<B> BfoldRight(B init, BiFunction<B, E, B> f) Same asfoldLeft(Object, BiFunction)but going from the right (the end of the list).booleanCheck whether the given predicate holds for all elements in this list.static <A> PList<A>fromArray(A[] values) Create a list from the given array.static <A> PList<A>Create a list from an iterable, by traversing the iterable and cons-ing each element.static <A> PList<A>fromNullable(A element) Return either the empty list ifelementisnull, or a singly element list with that element.static <A> PList<A>fromOptional(Optional<A> opt) Create a single element or the empty list from a given Optional.static <A,B> PList<B> Generate a list by using the output of the given function.<K> Map<K,NonEmptyList<E>> Return a map of lists that are keyed byf.inthashCode()abstract Ehead()Return the first element (the head) of this list.Returns the head of this list orOptional.empty()if this is the empty list.indexesOf(E element, BiPredicate<E, E> eq) Return all indexes of the given element.intindexOf(E element, BiPredicate<E, E> eq) Returns the first index of the given element or -1 if not found.abstract booleanisEmpty()Check whether this is the empty list.iterator()<B> PList<B>Applyfto each element in this list, returning a new list preserving this structure.max(Comparator<E> comparator) Return the maximum element according to the given comparator.min(Comparator<E> comparator) Return the minimum element according to the given comparator.Create a string wheresepappears between elements.static <A> PList<A>nil()Return the empty list.final booleannonEmpty()Check whether the list is not empty.static <A> PList<A>of(A... elements) Create a list from the given elements in the given order.range(int start, int end) Creates a list of integers, fromstarte(inclusive) toend(exclusive).reduce(BinaryOperator<E> f) Reduces this list to a single value using the merge functionf.reverse()Reverse the order of this list.static <A> PList<A>single(A element) Create a new single element list containing the given element.abstract intsize()Return the size of this list.sort(Comparator<E> comparator) Return a new sorted version of this list.tail()Returns the tail of this list, that is without first element.take(int count) Take the firstcountelements from this list.takeRight(int count) Return a new list with only the lastcountelements of this list.E[]Return a new array containing the elements of this list.Create a new mutableArrayListfrom this persistent list.static byte[]toByteArray(PList<Byte> list) Create a new primitive array of the given list.static double[]toDoubleArray(PList<Integer> list) Create a new primitive array of the given list.static float[]toFloatArray(PList<Integer> list) Create a new primitive array of the given list.Create a mutableHashSetfrom this persistent list.static int[]toIntArray(PList<Integer> list) Create a new primitive array of the given list.static long[]toLongArray(PList<Integer> list) Create a new primitive array of the given list.toStream()Create aStreamfrom this list.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
nil
Return the empty list.It is the same list for all
A. -
empty
Returns the empty list.It is the same list for all
A. -
cell
Create a “cons cell”, using the given head and tail. -
single
Create a new single element list containing the given element. -
fromNullable
Return either the empty list ifelementisnull, or a singly element list with that element.Note that
single(Object)would create a single-element list where the element isnull. -
generate
Generate a list by using the output of the given function. The function is called until it returnsOptional.empty(). -
of
Create a list from the given elements in the given order. -
fill
Create a list by calling the given supplierlengthtimes. -
range
Creates a list of integers, fromstarte(inclusive) toend(exclusive). -
fromIter
Create a list from an iterable, by traversing the iterable and cons-ing each element. The resulting list reflects the same order as the iterator of the given iterable emitted during traversal. -
fromOptional
Create a single element or the empty list from a given Optional. -
fromArray
Create a list from the given array. It returns a list in same order as the given array. @param values. -
collect
Traverse the iterator to create a new list. -
collector
A collector that can be used withStream.collect(Collector)to collect a stream into aPList. -
size
public abstract int size()Return the size of this list. The size is cached and doesn't require to traverse the list. -
tail
Returns the tail of this list, that is without first element. -
head
Return the first element (the head) of this list. An exception is thrown if this is the empty list. -
isEmpty
public abstract boolean isEmpty()Check whether this is the empty list. -
apply
- Specified by:
applyin interfaceIntFunction<E>
-
asFunction
-
concat
Concatenates the given list ontothislist. -
cons
Create a new list by addingelementto the beginning of this list. That is,elementbecomes the head andthisbecomes the tail of the new list. -
add
Create a new list by addingelementto the tail of this list, i. e. the head of the list remains the same. Use this method carefully as it is expensive, usecons(Object)if possible. -
contains
Check whether the given element is a member of this list. -
drop
Drop the firstcountelements of this list. Ifcountis greater than the size of this list, the empty list is returned. -
dropRight
Return a new list with the lastcountelements removed. -
exists
Check whether any element in this list holds the predicate. -
filter
Return a new list with only those elements ofthisthat holds the given predicate. -
filterWithNext
Filter this list by peeking the next element. The bi-predicate receives the current element as first argument and the next element as second argument. -
filterWithPrev
Filter this list by peeking the previous element. The bi-predicate receives the current element as the second argument and the previous as first. -
distinct
Remove duplicate elements. The returned list is sorted.A
Comparatoris used for determining whether two elements are a duplicate, because the list is first sorted, and then subsequent elements are compared, using the same comparator. If you can useequals/hashCodeto compare elements, thedistinct(Function)version is faster. -
distinct
Remove duplicate elements retaining the order. Duplicate elements are identified by usingObject.equals(Object)on the computed key of an element withgetKey. The first occurrence of an element is kept.If you want to specify a custom function to determine a duplicate, use
distinct(Comparator)instead. -
duplicates
Retain only elements that exists more than once. The returned list is sorted and each duplicate is appears once.A
Comparatoris used for determining whether two elements are a duplicate, because the list is first sorted, and then subsequent elements are compared, using the same comparator. -
find
Find the first element that holds the given predicate. -
flatMap
Applyfto each element in the list and concatenate the results. -
flatMapOptional
Applyfto each element in the list and concatenate the non-empty results. -
forall
Check whether the given predicate holds for all elements in this list. -
foldLeft
Folds the list from the left.The function f is applied to the
initelement and the first element of this list. Thenfis applied to the result and the second element in this list, and so on.If this list is empty, the init element is returned and
fis not invoked.The list is alwayes completely traversed.
- Parameters:
init- the initial elementf- the function merging each element to the result off
-
foldRight
Same asfoldLeft(Object, BiFunction)but going from the right (the end of the list).Note that this version is not recursive and therefore is stack-safe but lacks the early-return feature.
- Parameters:
init- the initial element of the foldf- the function merging the result offwith each element
-
groupBy
Return a map of lists that are keyed byf. -
headOption
Returns the head of this list orOptional.empty()if this is the empty list.Note: If the element exists but is
null, thenOptional.empty()is returned as well! -
indexOf
Returns the first index of the given element or -1 if not found. -
indexesOf
Return all indexes of the given element. -
iterator
-
map
Applyfto each element in this list, returning a new list preserving this structure. -
max
Return the maximum element according to the given comparator. -
min
Return the minimum element according to the given comparator. -
mkString
Create a string wheresepappears between elements. Elements are added using theirtoString()method. -
nonEmpty
public final boolean nonEmpty()Check whether the list is not empty. -
reduce
Reduces this list to a single value using the merge functionf. -
reverse
Reverse the order of this list. -
take
Take the firstcountelements from this list. -
takeRight
Return a new list with only the lastcountelements of this list. -
sort
Return a new sorted version of this list. -
toArrayList
Create a new mutableArrayListfrom this persistent list. -
toArray
Return a new array containing the elements of this list. -
toByteArray
Create a new primitive array of the given list. -
toIntArray
Create a new primitive array of the given list. -
toLongArray
Create a new primitive array of the given list. -
toFloatArray
Create a new primitive array of the given list. -
toDoubleArray
Create a new primitive array of the given list. -
toHashSet
Create a mutableHashSetfrom this persistent list. -
toStream
Create aStreamfrom this list. -
zipLazy
-
zip
-
zipWithIndex
-
toString
-
hashCode
public int hashCode() -
equals
-