E - Type of the elements in the iteratorpublic class LazyIter<E> extends Object implements Iterable<E>
Functional style lazy 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.
Most of the methods are lazy, they do not perform any action at the call time, but return either Iterable or Promise.
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 |
|---|---|
Promise<Boolean> |
all(Predicate<E> matcher)
Checks if all elements of collection match supplied predicate
|
Promise<Boolean> |
any(Predicate<E> matcher)
Checks if any of the elements of collection match supplied predicate
|
LazyIter<E> |
filter(Predicate<E> predicate)
Filters out elements of iterable collection based on predicate.
|
Promise<E> |
find(Predicate<E> matcher,
E defaultValue)
Finds element in collection that matches supplied
Predicate |
E |
head()
This method is not lazy
|
Iterator<E> |
iterator()
Returns
Iterator for the elements in this Iterable |
<R> LazyIter<R> |
map(Func<R,E> func)
Maps all the values in the collection to other values using supplied function.
|
static <E> LazyIter<E> |
of(Collection<E> coll)
Constructs new lazy iterable from collection.
|
static <E> LazyIter<E> |
of(E... data)
Create new lazy iterable from array, sequence of parameters.
|
static <E> LazyIter<E> |
of(E head,
Collection<E> tail) |
<R> Promise<R> |
reduce(R starting,
Function2<R,R,E> f)
Folds iterable collection left
|
LazyIter<E> |
tail()
This method is not lazy
|
E[] |
toArray(E[] array)
Returns an array containing all elements contained in this Iterable.
|
List<E> |
toList()
This method is not lazy
|
Set<E> |
toSet()
This method is not lazy
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static <E> LazyIter<E> of(Collection<E> coll)
E - type of collection elementscoll - collectionpublic static <E> LazyIter<E> of(E head, Collection<E> tail)
public static <E> LazyIter<E> of(E... data)
E - type of elementsdata - array or varargspublic List<E> toList()
List containing all the items from this collection. Returned list is immutablepublic Set<E> toSet()
Set containing all the items from this collection. Returned list is immutablepublic E[] toArray(E[] array)
Returns an array containing all elements contained in this Iterable. If the specified array is large enough to hold the elements, the specified array is used, otherwise an array of the same type is created. If the specified array is used and is larger than this List, the array element following the collection elements is set to null.
array - the arrayArrayStoreException - if the type of an element in this List cannot be stored in the type of the specified array.public <R> LazyIter<R> map(Func<R,E> func)
Maps all the values in the collection to other values using supplied function.
This function will not create new collection, instead transformation function will be applied to
the next original collection's element during each call to Iterator.next()
R - result typefunc - mapping functionpublic <R> Promise<R> reduce(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 LazyIter<E> filter(Predicate<E> predicate)
true if the element must be included into resulting collection or false otherwise.predicate - - function to verify collection elementIterable collection. This function will not create resulting collection immediately, instead next
element will be evaluated when requested with Iterator.next()public E head()
NoSuchElementException - if collection is emptypublic LazyIter<E> tail()
NoSuchElementException - if collection is emptypublic Promise<E> find(Predicate<E> matcher, E defaultValue)
Predicatepublic Promise<Boolean> all(Predicate<E> matcher)
Copyright © 2018. All rights reserved.