public final class Iterate extends Object
lists
, sets
, or any implementation
of Iterable
. Can also
treat Strings as a container of Characters
.Modifier and Type | Field and Description |
---|---|
static Predicate<Iterable<?>> |
empty
Evaluates if an
Iterable is empty. |
static Predicate<Iterator<?>> |
hasNext
The
Iterator.hasNext() method as a function. |
static Fn<Collection<?>,Integer> |
size
|
Modifier and Type | Method and Description |
---|---|
static <T,P extends Comparable<P>> |
by(Fn<T,P> property)
|
static <T extends Comparable<T>> |
byOrderingOf(Class<T> comparableType)
Convert a type with natural ordering, i.e. implements
Comparable , to
an external Comparator . |
static <T> Fn<T,T> |
last(Fn<? super T,? extends T> next)
Using a function which takes an object and returns another object of the same type,
recursively call this function until it yields
null , and ultimately yield the
last object. |
static <T> Fn<Iterator<T>,T> |
next() |
static <T> Elements<T> |
none() |
static Elements<Byte> |
on(byte[] bytes)
Work with multiple bytes.
|
static Elements<Character> |
on(CharSequence string)
Manipulate CharSequences/Strings as if they were iterables of
Characters.
|
static <T> Elements<T> |
on(Iterable<T> elements)
Work with multiple elements.
|
static <K,V> Elements<Map.Entry<K,V>> |
on(Map<K,V> map) |
static <T> Elements<T> |
on(T... elements)
Work with multiple elements.
|
static <I,O> Fn<I,Iterable<O>> |
toIterable(Fn<I,O[]> yieldsArray)
A bridge from functions yielding arrays, to functions yielding iterables.
|
public static final Predicate<Iterator<?>> hasNext
Iterator.hasNext()
method as a function.public static final Fn<Collection<?>,Integer> size
public static <T> Elements<T> none()
Elements
container.public static Elements<Character> on(CharSequence string)
string
- The stringElements
characters@SafeVarargs public static <T> Elements<T> on(T... elements)
elements
- the elements to manipulate as vararg/array.Elements
public static Elements<Byte> on(byte[] bytes)
bytes
- the bytes to manipulate as vararg/array.public static <T,P extends Comparable<P>> EnhancedComparator<T> by(Fn<T,P> property)
property
- the Fn
which obtains the comparable propertyComparator
using the value yielded from the given Fn
.public static <T extends Comparable<T>> EnhancedComparator<T> byOrderingOf(Class<T> comparableType)
Comparable
, to
an external Comparator
. This is a little quirk to provide a typesafe
way to sort iterables containing Comparables
, instead of risking
a runtime ClassCastException. Pass this to the
.sorted(..)
method to get elements as a sorted list.comparableType
- The Comparable
type to create a Comparator
from.Comparator
public static final <T> Fn<Iterator<T>,T> next()
Iterator.next()
as a function.public static <T> Fn<T,T> last(Fn<? super T,? extends T> next)
null
, and ultimately yield the
last object.next
- The function which takes an object and yields another object of the same type.
This is typically used for objects implementing a linked list-like structure,
where each object refers to the next in a chain.next
Fn
never returns null
, calling this
returned function will result in an infinite recursion.public static <I,O> Fn<I,Iterable<O>> toIterable(Fn<I,O[]> yieldsArray)
yieldsArray
- the array-yielding function.Copyright © 2016. All rights reserved.