@Test public void testNextWithOnlyUsingNextMethod() { Subject<String, String> obs = PublishSubject.create(); Iterator<String> it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertEquals("one", it.next()); fireOnNextInNewThread(obs, "two"); assertEquals("two", it.next()); obs.onCompleted(); try { it.next(); fail("At the end of an iterator should throw a NoSuchElementException"); } catch (NoSuchElementException e) { } }
public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; } }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  static Iterable<T> next(final Observable<? extends T> items); }
OperationNext { public static <T> Iterable<T> next(final Observable<? extends T> items) { return new Iterable<T>() { @Override public Iterator<T> iterator() { NextObserver<T> nextObserver = new NextObserver<T>(); final NextIterator<T> nextIterator = new NextIterator<T>(nextObserver); items.materialize().subscribe(nextObserver); return nextIterator; } }; }  static Iterable<T> next(final Observable<? extends T> items);  }