[ 
https://issues.apache.org/jira/browse/COLLECTIONS-870?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved COLLECTIONS-870.
-----------------------------------------
    Fix Version/s: 4.5.0-M3
       Resolution: Fixed

> Add an ExtendedIterator to support streaming idiomatic usage.
> -------------------------------------------------------------
>
>                 Key: COLLECTIONS-870
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-870
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Iterator
>    Affects Versions: 4.5.0-M2
>            Reporter: Claude Warren
>            Assignee: Claude Warren
>            Priority: Major
>             Fix For: 4.5.0-M3
>
>
> I would like to introduce a new Iterator to the iterator library: 
> ExtendedIterator
>  
> This Iterator is an Iterator that extends the functionality of other 
> iterators and makes using some iterators in the library more idiomatic.  It 
> is based on the ExtendedIterator found in the new Apache Rat core package 
> that was inspired by the Apache Jena ExtendedIterator interface.
>  
> I propose a class ExtendedIterator<T> that extends Iterator<T> and has the 
> following additional methods. 
>  
> Static methods (all methods return an ExtendedIterator<T>) * 
> createNoRemove(final Iterator<T> it) -- prohibits removal on an iterator that 
> otherwise would allow removal.
>  * create(final Stream<T> stream) -- convenience method to create 
> ExtendedIterator from stream.
>  * create(final Iterator<T> it)-- creates an ExtendedIterator from a plain 
> iterator.  If the Iterator is already "extended" just return it.
>  * emptyIterator() -- convenience method to creat an empty ExtendedIterator.
>  * flatten(final Iterator<Iterator<T>> iteratorIterator) -- creates an 
> Iterator<T> by iterating through each of the iterators in "iteratorIterator"
>  
> Instance methods (Unless otherwise noted all methods return an 
> ExtendedIterator<T>) * T removeNext() -- extracts the next item from the 
> iterator and calls remove() to remove it.
>  * andThen(final Iterator<X> other)-- <X extends T> uses an IteratorChain to 
> create a chain of iterators.
>  * filter(final Predicate<T> predicate) -- uses a FilterIterator to exclude 
> the items from the iterator.
>  * ExtendedIterator<U> map(final Function<T, U> function) -- uses a 
> TransformerIterator to transform the items to a new type.
>  * <U extends Collection<T>> U addTo(final U collection) -- Adds the 
> remaining items in the iterator to the collection.
>  
> The advantage of the iterator is the idiomatic nature.
>  
> {{Iterator<Thing> iter;}}
> {{List<OtherThing> lst = 
> ExtendedIteratot.create(iter).filter(Thing::isValid).map(thing -> new 
> OtherThing(thing)).addTo(new ArrayList<>());}}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to