Skip to content

Commit

Permalink
Fix aNNiMON#4. Custom Iterator for list.
Browse files Browse the repository at this point in the history
  • Loading branch information
aNNiMON committed Jul 21, 2015
1 parent 9c303c2 commit 6c595e7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/com/annimon/stream/Stream.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
*/
public class Stream<T> {

public static <T> Stream<T> of(final List<? extends T> list) {
return new Stream<T>(new Iterator<T>() {

private int index = 0;

@Override
public boolean hasNext() {
return index < list.size();
}

@Override
public T next() {
return list.get(index++);
}
});
}

public static <T> Stream<T> of(Iterator<? extends T> iterator) {
return new Stream<T>(iterator);
}
Expand Down

0 comments on commit 6c595e7

Please sign in to comment.