E - Type of the elements in the iteratorpublic class Iter<E> extends Object implements Iterable<E>
Functional style immutable rich iterator
Main difference from standard Iterator is that this iterator allows functions to be applied to the elements.
It supports standard operations like filter(Predicate), map(Func)
or reduce(Object, Function2) and others.
This is essentially a rich wrapper around Iterator over collection. Standard limitations of iterators apply,
like restriction of changing collection during iteration
| Modifier and Type | Method and Description |
|---|---|
boolean |
all(Predicate<E> matcher)
Checks if all elements of iterator match supplied predicate
|
boolean |
any(Predicate<E> matcher)
Checks if any of the elements of iterator match supplied predicate
|
Collection<E> |
collectWith(Collector<E> collector)
Collect this iterable into collection
|
Iter<E> |
filter(Predicate<E> predicate)
Filters out elements of iterable iterator based on predicate.
|
E |
find(Predicate<E> matcher,
E defaultValue)
Finds first element in iterator that matches supplied
Predicate |
void |
forEach(Procedure<E> executor)
Calls specified
Procedure for each element |
static <E> Iter<E> |
fromArray(E[] data)
Creates rich iterator wrapper around array of elements
|
Iterator<E> |
iterator() |
Promise<E> |
lazyFind(Predicate<E> matcher,
E defaultValue)
Lazy variant of
find(Predicate, Object) |
<R> Promise<R> |
lazyReduce(R starting,
Function2<R,R,E> f)
Lazily folds iterable iterator left
|
<R> Iter<R> |
map(Func<R,E> func)
Maps all the values in the iterator to other values using supplied function.
|
String |
mkStr(String separator)
Joins all the elements in the collection into string with supplied separator
|
static <E> Iter<E> |
of(Collection<E> coll)
Creates iterator over collection.
|
static <E> Iter<E> |
of(E... data)
Creates rich iterator wrapper around array of elements
|
static <E> Iter<E> |
of(Enumeration<E> enumeration) |
static <E> Iter<E> |
of(Iterator<E> iter)
Creates rich iterator wrapper around Java
Iterator. |
<R> R |
reduce(R starting,
Function2<R,R,E> f)
Folds iterable iterator left
|
E[] |
toArray(Class<E> arrayType)
Returns an array containing all of the elements in this iterable in proper sequence (from first to last element);
the runtime type of the returned array is that of the specified array.
|
E[] |
toArray(E[] array)
Returns an array containing all of the elements in this iterable in proper sequence (from first to last element);
the runtime type of the returned array is that of the specified array.
|
List<E> |
toList() |
<K> Map<K,E> |
toMap(Func<K,E> keyGenerator)
Converts this iterable into map using provided key generator function.
|
Set<E> |
toSet() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static <E> Iter<E> of(Enumeration<E> enumeration)
public static <E> Iter<E> of(Collection<E> coll)
ConcurrentModificationException may be thrown.E - type of elements in the collectioncoll - collection to be wrappedpublic static <E> Iter<E> of(Iterator<E> iter)
Creates rich iterator wrapper around Java Iterator.
Do not use wrapped iterator as it will interfere with operations over rich iterator.
E - type of elements in the collectioniter - Iterator to wrap with rich functionalitypublic static <E> Iter<E> of(E... data)
Creates rich iterator wrapper around array of elements
This iterator is created over copy of the array, so original array can be used or disposed of.
E - type of elementsdata - the arraypublic static <E> Iter<E> fromArray(E[] data)
E - Array element typedata - Array to create iterator forpublic List<E> toList()
List containing all the items from this iterator. Returned list is immutablepublic Set<E> toSet()
Set containing all the items from this iterator. Returned list is immutablepublic E[] toArray(E[] array)
Returns an array containing all of the elements in this iterable in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Iterable.
If the list fits in the specified array with room to spare (i.e., the array has more elements than the iterable), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
array - the array into which the elements of this list are to be stored, if it is big enough; otherwise,
a new array of the same runtime type is allocated for this purpose.public E[] toArray(Class<E> arrayType)
Returns an array containing all of the elements in this iterable in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Iterable.
If the list fits in the specified array with room to spare (i.e., the array has more elements than the iterable), the element in the array immediately following the end of the list is set to null. (This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.)
arrayType - Type of the array elementpublic <R> Iter<R> map(Func<R,E> func)
Maps all the values in the iterator to other values using supplied function.
This function will not create new iterator, instead transformation function will be applied to
the next original iterator's element during each call to Iterator.next()
R - result typefunc - mapping functionpublic void forEach(Procedure<E> executor)
Procedure for each elementexecutor - Procedure to be executed on each element of iterablepublic <R> R reduce(R starting,
Function2<R,R,E> f)
R - type of the resulting valuestarting - initial value of the resultf - folding functionpublic <R> Promise<R> lazyReduce(R starting, Function2<R,R,E> f)
R - type of the resulting valuestarting - initial value of the resultf - folding functionPromise of the value of the left-folded collectionpublic Iter<E> filter(Predicate<E> predicate)
true if the element must be included into resulting iterator or false otherwise.predicate - - function to verify iterator elementIterable iterator. This function will not create resulting iterator immediately, instead next
element will be evaluated when requested with Iterator.next()public E find(Predicate<E> matcher, E defaultValue)
Predicatematcher - Predicate to test iterator's elementsdefaultValue - default value that will be returned if none of the elements in the iterator matches predicatepublic Promise<E> lazyFind(Predicate<E> matcher, E defaultValue)
find(Predicate, Object)matcher - Predicate to test iterator elementsdefaultValue - default value that will be returned if none of the elements in the iterator matches predicatepublic boolean all(Predicate<E> matcher)
matcher - - Predicate to check elementstrue if all elements match predicate or false otherwisepublic boolean any(Predicate<E> matcher)
matcher - - Predicate to check elementstrue if any of the elements match predicate or false otherwisepublic String mkStr(String separator)
separator - string to separate elementspublic Collection<E> collectWith(Collector<E> collector)
collector - Collector which will perform collectionCollection of all the elements in this iterablepublic <K> Map<K,E> toMap(Func<K,E> keyGenerator)
For each element map key is generated using keyGenerator and key->element pair is inserted into the map. Generated map is unmodifiable.
K - Type of the key.keyGenerator - Key generator function which should create a key from the iterable element.Copyright © 2018. All rights reserved.