Skip to content

Commit

Permalink
Merge branch 'replace-iterator-with-tryadvance' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
fmcarvalho committed Oct 19, 2020
2 parents 124bc9d + e3db7b5 commit 77e2391
Show file tree
Hide file tree
Showing 113 changed files with 2,545 additions and 2,867 deletions.
32 changes: 9 additions & 23 deletions src/main/java/org/jayield/Advancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,20 @@

package org.jayield;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
* Sequential traverser with both internal and external iteration approach.
* Sequential traverser with internal and individually step approach.
*/
public interface Advancer<T> extends Iterator<T>, Traverser<T> {
public interface Advancer<T> {
/**
* If a remaining element exists, yields that element through
* the given action.
*/
boolean tryAdvance(Yield<? super T> yield);

/**
* An Advancer object without elements.
*/
static <R> Advancer<R> empty() {
return new Advancer<R>() {
@Override
public boolean hasNext() {
return false;
}

@Override
public R next() {
throw new NoSuchElementException("No such elements available for iteration!");
}

@Override
public void traverse(Yield<? super R> yield) {
/* Do nothing. Since there are no elements, thus there is nothing to do. */
}
};
return action -> false;
}


}
Loading

0 comments on commit 77e2391

Please sign in to comment.