Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Observable.startWith(Observable) method and unit test #934

Merged
merged 2 commits into from
Mar 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6431,6 +6431,22 @@ public final Observable<T> skipWhileWithIndex(Func2<? super T, Integer, Boolean>
return create(OperationSkipWhile.skipWhileWithIndex(this, predicate));
}

/**
* Returns an Observable that emits the items in a specified {@link Observable} before it begins to emit items
* emitted by the source Observable.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/startWith.png">
*
* @param values
* an Observable that contains the items you want the modified Observable to emit first
* @return an Observable that emits the items in the specified {@link Observable} and then emits the items
* emitted by the source Observable
* @see <a href="https://github.com/Netflix/RxJava/wiki/Combining-Observables#wiki-startwith">RxJava Wiki: startWith()</a>
*/
public final Observable<T> startWith(Observable<T> values) {
return concat(values, this);
}

/**
* Returns an Observable that emits the items in a specified {@link Iterable} before it begins to emit items
* emitted by the source Observable.
Expand Down
13 changes: 13 additions & 0 deletions rxjava-core/src/test/java/rx/StartWithTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,17 @@ public void startWithIterable() {
assertEquals("two", values.get(3));
}

@Test
public void startWithObservable() {
List<String> li = new ArrayList<String>();
li.add("alpha");
li.add("beta");
List<String> values = Observable.from("one", "two").startWith(Observable.from(li)).toList().toBlockingObservable().single();

assertEquals("alpha", values.get(0));
assertEquals("beta", values.get(1));
assertEquals("one", values.get(2));
assertEquals("two", values.get(3));
}

}