Skip to content

Instantly share code, notes, and snippets.

@stepango
Created April 7, 2017 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stepango/dd6f326cccb499f940cda7f8a7b64658 to your computer and use it in GitHub Desktop.
Save stepango/dd6f326cccb499f940cda7f8a7b64658 to your computer and use it in GitHub Desktop.
Arguments forwarding test
class RxTest {
@Test fun forward() {
fun <T : Any, R : Any> Observable<T>.forwardFlatMap(block: () -> Observable<R>): Observable<Pair<T, R>>
= flatMap { item -> block().map { item to it } }
Observable.just("")
.flatMap { str ->
Observable.just(1)
.map { str to it }
}
.map { (x, y) -> "$x$y" }
.test()
.assertValue("1")
Observable.just("")
.forwardFlatMap { Observable.just(1) }
.map { (x, y) -> "$x$y" }
.test()
.assertValue("1")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment