public final class NonEmptyList<A>
extends java.lang.Object
implements java.lang.Iterable<A>
head
and tail
.Modifier and Type | Method and Description |
---|---|
NonEmptyList<A> |
append(List<A> as)
Appends the given list to this list.
|
NonEmptyList<A> |
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.
|
NonEmptyList<A> |
cons(A a)
Prepend the given value to this list.
|
boolean |
equals(java.lang.Object obj)
Perform an equality test on this list which delegates to the .equals() method of the member instances.
|
A |
foldLeft1(F<A,F<A,A>> f)
Performs a left-fold reduction across this list.
|
A |
foldLeft1(F2<A,A,A> f)
Performs a left-fold reduction across this list.
|
A |
foldRight1(F<A,F<A,A>> f)
Performs a right-fold reduction across this list.
|
A |
foldRight1(F2<A,A,A> f)
Performs a right-fold reduction across this list.
|
static <A> Option<NonEmptyList<A>> |
fromList(List<A> as)
Returns a potential non-empty list from the given list.
|
int |
hashCode() |
A |
head()
The first element of this linked list.
|
NonEmptyList<A> |
intersperse(A a)
Intersperses the given argument between each element of this non empty list.
|
java.util.Iterator<A> |
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.
|
int |
length()
The length of this list.
|
<B> NonEmptyList<B> |
map(F<A,B> f)
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).
|
A |
maximum(Ord<A> o)
Returns the maximum element in this non empty list according to the given ordering.
|
A |
minimum(Ord<A> o)
Returns 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> |
nel(A head,
List<A> tail)
Return a non-empty list with the given head and tail.
|
NonEmptyList<A> |
reverse()
Reverse this non empty list in constant stack space.
|
NonEmptyList<A> |
snoc(A a)
Appends (snoc) the given element to this non empty list to produce a new non empty list.
|
NonEmptyList<A> |
sort(Ord<A> o)
Sorts this non empty list using the given order over elements using a merge sort algorithm.
|
NonEmptyList<NonEmptyList<A>> |
sublists()
Returns a NonEmptyList of the sublists of this list.
|
List<A> |
tail()
This list without the first element.
|
NonEmptyList<NonEmptyList<A>> |
tails()
Returns a NonEmptyList of the tails of this list.
|
java.util.Collection<A> |
toCollection()
Projects an immutable collection of this non-empty list.
|
static <A> F<NonEmptyList<A>,List<A>> |
toList_()
Returns a function that takes a non-empty list to a list.
|
List<A> |
toList()
Returns a
List projection of this list. |
java.lang.String |
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.
|
NonEmptyList<P2<A,java.lang.Integer>> |
zipIndex()
Zips this non empty list with the index of its element as a pair.
|
<B,C> NonEmptyList<C> |
zipWith(List<B> bs,
F<A,F<B,C>> f)
Zips this non empty list with the given non empty list using the given function to produce a new list.
|
<B,C> NonEmptyList<C> |
zipWith(List<B> bs,
F2<A,B,C> f)
Zips this non empty list with the given non empty list using the given function to produce a new list.
|
public java.util.Iterator<A> iterator()
for
-each loop.iterator
in interface java.lang.Iterable<A>
public A head()
public NonEmptyList<A> cons(A a)
a
- The value to prepend.public NonEmptyList<A> snoc(A a)
a
- The element to append to this non empty list.public int length()
public NonEmptyList<A> append(List<A> as)
as
- The list to append.public NonEmptyList<A> append(NonEmptyList<A> as)
as
- The list to append.public final A foldRight1(F<A,F<A,A>> f)
public final A foldRight1(F2<A,A,A> f)
public final A foldLeft1(F<A,F<A,A>> f)
public final A foldLeft1(F2<A,A,A> f)
public <B> NonEmptyList<B> map(F<A,B> f)
f
- The function to map across this list.public <B> NonEmptyList<B> bind(F<A,NonEmptyList<B>> f)
f
- The function to apply to each element of this list.public NonEmptyList<NonEmptyList<A>> sublists()
public NonEmptyList<NonEmptyList<A>> tails()
public <B> NonEmptyList<B> mapTails(F<NonEmptyList<A>,B> f)
f
- The function to map across the tails of this list.public NonEmptyList<A> intersperse(A a)
a
- The separator to intersperse in this non empty list.public NonEmptyList<A> reverse()
public NonEmptyList<A> sort(Ord<A> o)
o
- The order over the elements of this non empty list.public final A minimum(Ord<A> o)
o
- An ordering for the elements of this non empty list.public final A maximum(Ord<A> o)
o
- An ordering for the elements of this non empty list.public <B> NonEmptyList<P2<A,B>> zip(NonEmptyList<B> bs)
bs
- The non empty list to zip this non empty list with.public NonEmptyList<P2<A,java.lang.Integer>> zipIndex()
public <B,C> NonEmptyList<C> zipWith(List<B> bs, F<A,F<B,C>> f)
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.public <B,C> NonEmptyList<C> zipWith(List<B> bs, F2<A,B,C> f)
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.public static <A,B> P2<NonEmptyList<A>,NonEmptyList<B>> unzip(NonEmptyList<P2<A,B>> xs)
xs
- The non empty list of pairs to transform.public List<A> toList()
List
projection of this list.List
projection of this list.public java.util.Collection<A> toCollection()
public static <A> F<NonEmptyList<A>,List<A>> toList_()
public static <A> NonEmptyList<A> nel(A head, List<A> tail)
head
- The first element of the new list.tail
- The remaining elements of the new list.@SafeVarargs public static <A> NonEmptyList<A> nel(A head, A... tail)
head
- The first in the non-empty list.tail
- The elements to construct a list's tail with.public static <A> F<A,NonEmptyList<A>> nel()
public static <A> Option<NonEmptyList<A>> fromList(List<A> as)
as
- The list to construct a potential non-empty list with.public static <A> NonEmptyList<A> join(NonEmptyList<NonEmptyList<A>> o)
o
- The non empty list of non empty lists to join.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the other object to check for equality against.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object