@Test public void testMostRecent() { Subject<String, String> s = PublishSubject.create(); Iterator<String> it = mostRecent(s, "default").iterator(); assertTrue(it.hasNext()); assertEquals("default", it.next()); assertEquals("default", it.next()); s.onNext("one"); assertTrue(it.hasNext()); assertEquals("one", it.next()); assertEquals("one", it.next()); s.onNext("two"); assertTrue(it.hasNext()); assertEquals("two", it.next()); assertEquals("two", it.next()); s.onCompleted(); assertFalse(it.hasNext()); }
public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); } }; }
BlockingOperatorMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); } }; } }
BlockingOperatorMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); } }; } private  BlockingOperatorMostRecent(); }
BlockingOperatorMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); } }; } private  BlockingOperatorMostRecent(); static Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue); }
BlockingOperatorMostRecent { public static <T> Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue) { return new Iterable<T>() { @Override public Iterator<T> iterator() { MostRecentObserver<T> mostRecentObserver = new MostRecentObserver<T>(initialValue); source.subscribe(mostRecentObserver); return mostRecentObserver.getIterable(); } }; } private  BlockingOperatorMostRecent(); static Iterable<T> mostRecent(final Observable<? extends T> source, final T initialValue);  }