Skip to content

Instantly share code, notes, and snippets.

@n8han
Last active December 14, 2015 16:40
Show Gist options
  • Save n8han/4497ce3c2fbd3830a36a to your computer and use it in GitHub Desktop.
Save n8han/4497ce3c2fbd3830a36a to your computer and use it in GitHub Desktop.
When a source observable emits, skip any further emissions until a second observable completes
public static <A, B> Observable<B> skipMap(Observable<A> source, Func1<A, Observable<B>> action) {
return source.first().flatMap(a -> Observable.concat(action.call(a), skipMap(source, action)));
}
@n8han
Copy link
Author

n8han commented Dec 14, 2015

My use case is attaching a tap listener to an asynchronous task. Is there not an operator with these characteristics included in RxJava?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment