Package ch.bluecare.commons.data
Class NonEmptyList<A>
java.lang.Object
ch.bluecare.commons.data.NonEmptyList<A>
- All Implemented Interfaces:
Iterable<A>,IntFunction<A>
A
PList that has at least one element.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreate a new list by addingelementto the tail of this list, i.apply(int value) Appends an iterable to this list.Prepend the given element to this list.boolean<B> NonEmptyList<B>flatMap(Function<A, NonEmptyList<B>> f) Apply the function to every element and flatten the results.static <A> Optional<NonEmptyList<A>>Create a non-empty list from a given iterable.inthashCode()head()Return the head of this list.iterator()<B> NonEmptyList<B>Map the given function across this list.static <A> NonEmptyList<A>of(A first, A... other) reduce(BinaryOperator<A> f) Reduces this list to a single value using the merge functionf.reverse()Reverses this list.static <A> NonEmptyList<A>single(A el) Creates a single-element list.intsize()sort(Comparator<A> comparator) Sorts this list according to the given comparator.tail()Return the tail of this list.toPList()Convert this to aPListwhich will be non-empty.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
NonEmptyList
-
-
Method Details
-
of
-
single
Creates a single-element list. -
fromIter
Create a non-empty list from a given iterable. Use the various constructors onPListto create iterables from other values. -
head
Return the head of this list. -
tail
Return the tail of this list. -
concat
Appends an iterable to this list. -
cons
Prepend the given element to this 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, usePList.cons(Object)if possible. -
map
Map the given function across this list. -
flatMap
Apply the function to every element and flatten the results. -
reduce
Reduces this list to a single value using the merge functionf. -
reverse
Reverses this list. -
sort
Sorts this list according to the given comparator. -
size
public int size() -
toPList
Convert this to aPListwhich will be non-empty. -
zipWithIndex
-
apply
- Specified by:
applyin interfaceIntFunction<A>
-
iterator
-
equals
-
hashCode
public int hashCode() -
toString
-