Class NonEmptyList<A>
java.lang.Object
fj.data.NonEmptyList<A>
- All Implemented Interfaces:
Iterable<A>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the given list to this list.append(NonEmptyList<A> as) Appends the given list to this list.<B> NonEmptyList<B> bind(F<A, NonEmptyList<B>> f) Binds the given function across each element of this list with a final join.Prepend the given value to this list.booleanPerform an equality test on this list which delegates to the .equals() method of the member instances.final APerforms a left-fold reduction across this list.final APerforms a left-fold reduction across this list.final APerforms a right-fold reduction across this list.final AfoldRight1(F2<A, A, A> f) Performs a right-fold reduction across this list.static <A> Option<NonEmptyList<A>> Returns a potential non-empty list from the given list.inthashCode()head()The first element of this linked list.intersperse(A a) Intersperses the given argument between each element of this non empty list.iterator()Returns an iterator for this non-empty list.static <A> NonEmptyList<A> join(NonEmptyList<NonEmptyList<A>> o) Concatenate (join) a non empty list of non empty lists.intlength()The length of this list.<B> NonEmptyList<B> Maps the given function across this list.<B> NonEmptyList<B> mapTails(F<NonEmptyList<A>, B> f) Maps the given function across the tails of this list (comonad pattern).final AReturns the maximum element in this non empty list according to the given ordering.final AReturns the minimum element in this non empty list according to the given ordering.static <A> F<A, NonEmptyList<A>> nel()Returns a function that puts an element into a non-empty list.static <A> NonEmptyList<A> nel(A head, A... tail) Constructs a non empty list from the given elements.static <A> NonEmptyList<A> Return a non-empty list with the given head and tail.reverse()Reverse this non empty list in constant stack space.Appends (snoc) the given element to this non empty list to produce a new non empty list.Sorts this non empty list using the given order over elements using a merge sort algorithm.sublists()Returns a NonEmptyList of the sublists of this list.tail()This list without the first element.tails()Returns a NonEmptyList of the tails of this list.Projects an immutable collection of this non-empty list.toList()Returns aListprojection of this list.static <A> F<NonEmptyList<A>, List<A>> toList_()Returns a function that takes a non-empty list to a list.toString()static <A,B> P2 <NonEmptyList<A>, NonEmptyList<B>> unzip(NonEmptyList<P2<A, B>> xs) Transforms a non empty list of pairs into a non empty list of first components and a non empty list of second components.<B> NonEmptyList<P2<A, B>> zip(NonEmptyList<B> bs) Zips this non empty list with the given non empty list to produce a list of pairs.zipIndex()Zips this non empty list with the index of its element as a pair.<B,C> NonEmptyList <C> Zips this non empty list with the given non empty list using the given function to produce a new list.<B,C> NonEmptyList <C> Zips this non empty list with the given non empty list using the given function to produce a new list.Methods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
head
-
tail
-
-
Constructor Details
-
NonEmptyList
-
-
Method Details
-
iterator
-
head
The first element of this linked list. -
tail
-
cons
Prepend the given value to this list.- Parameters:
a- The value to prepend.- Returns:
- A non-empty list with an extra element.
-
snoc
Appends (snoc) the given element to this non empty list to produce a new non empty list. O(n).- Parameters:
a- The element to append to this non empty list.- Returns:
- A new non empty list with the given element appended.
-
length
public int length()The length of this list.- Returns:
- The length of this list.
-
append
Appends the given list to this list.- Parameters:
as- The list to append.- Returns:
- A new list with the given list appended.
-
append
Appends the given list to this list.- Parameters:
as- The list to append.- Returns:
- A new list with the given list appended.
-
foldRight1
-
foldRight1
-
foldLeft1
-
foldLeft1
-
map
Maps the given function across this list.- Parameters:
f- The function to map across this list.- Returns:
- A new list after the given function has been applied to each element.
-
bind
Binds the given function across each element of this list with a final join.- Parameters:
f- The function to apply to each element of this list.- Returns:
- A new list after performing the map, then final join.
-
sublists
Returns a NonEmptyList of the sublists of this list.- Returns:
- a NonEmptyList of the sublists of this list.
-
tails
Returns a NonEmptyList of the tails of this list. A list is considered a tail of itself for the purpose of this function (Comonad pattern).- Returns:
- A NonEmptyList of the tails of this list.
-
mapTails
Maps the given function across the tails of this list (comonad pattern).- Parameters:
f- The function to map across the tails of this list.- Returns:
- The results of applying the given function to the tails of this list, as a NonEmptyList.
-
intersperse
Intersperses the given argument between each element of this non empty list.- Parameters:
a- The separator to intersperse in this non empty list.- Returns:
- A non empty list with the given separator interspersed.
-
reverse
Reverse this non empty list in constant stack space.- Returns:
- A new non empty list with the elements in reverse order.
-
sort
Sorts this non empty list using the given order over elements using a merge sort algorithm.- Parameters:
o- The order over the elements of this non empty list.- Returns:
- A sorted non empty list according to the given order.
-
minimum
-
maximum
-
zip
Zips this non empty list with the given non empty list to produce a list of pairs. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.- Parameters:
bs- The non empty list to zip this non empty list with.- Returns:
- A new non empty list with a length the same as the shortest of this list and the given list.
-
zipIndex
Zips this non empty list with the index of its element as a pair.- Returns:
- A new non empty list with the same length as this list.
-
zipWith
Zips this non empty list with the given non empty list using the given function to produce a new list. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.- Parameters:
bs- The non empty list to zip this non empty list with.f- The function to zip this non empty list and the given non empty list with.- Returns:
- A new non empty list with a length the same as the shortest of this list and the given list.
-
zipWith
Zips this non empty list with the given non empty list using the given function to produce a new list. If this list and the given list have different lengths, then the longer list is normalised so this function never fails.- Parameters:
bs- The non empty list to zip this non empty list with.f- The function to zip this non empty list and the given non empty list with.- Returns:
- A new non empty list with a length the same as the shortest of this list and the given list.
-
unzip
Transforms a non empty list of pairs into a non empty list of first components and a non empty list of second components.- Parameters:
xs- The non empty list of pairs to transform.- Returns:
- A non empty list of first components and a non empty list of second components.
-
toList
-
toCollection
Projects an immutable collection of this non-empty list.- Returns:
- An immutable collection of this non-empty list.
-
toList_
Returns a function that takes a non-empty list to a list.- Returns:
- A function that takes a non-empty list to a list.
-
nel
Return a non-empty list with the given head and tail.- Parameters:
head- The first element of the new list.tail- The remaining elements of the new list.- Returns:
- A non-empty list with the given head and tail.
-
nel
Constructs a non empty list from the given elements.- Parameters:
head- The first in the non-empty list.tail- The elements to construct a list's tail with.- Returns:
- A non-empty list with the given elements.
-
nel
Returns a function that puts an element into a non-empty list.- Returns:
- A function that puts an element into a non-empty list.
-
fromList
Returns a potential non-empty list from the given list. A non-value is returned if the given list is empty.- Parameters:
as- The list to construct a potential non-empty list with.- Returns:
- A potential non-empty list from the given list.
-
join
Concatenate (join) a non empty list of non empty lists.- Parameters:
o- The non empty list of non empty lists to join.- Returns:
- A new non empty list that is the concatenation of the given lists.
-
equals
Perform an equality test on this list which delegates to the .equals() method of the member instances. This is implemented with Equal.nonEmptyListEqual using the anyEqual rule. -
hashCode
-
toString
-