Skip to content

Instantly share code, notes, and snippets.

@invasionofsmallcubes
Created February 20, 2017 23:05
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 invasionofsmallcubes/80f36a2b15af2767aec291cb6ab05d50 to your computer and use it in GitHub Desktop.
Save invasionofsmallcubes/80f36a2b15af2767aec291cb6ab05d50 to your computer and use it in GitHub Desktop.
Page 102 of your book
// Question is totally stupid but...
// Example on the book:
Observable<Observable<String>> delay = just(
alice.map(w -> "MOO Alice: " + w),
paolo.map(w -> "MOO Paolo: " + w),
carmelo.map(w -> "MOO Carmelo: " + w)
)
.flatMap(Observable::just)
.delay(random.nextInt(5), SECONDS);
// what is the difference with:
Observable<Observable<String>> delay = just(
alice.map(w -> "MOO Alice: " + w),
paolo.map(w -> "MOO Paolo: " + w),
carmelo.map(w -> "MOO Carmelo: " + w)
)
.delay(random.nextInt(5), SECONDS);
// Running with
switchOnNext(delay).subscribe(out::println);
// gives the same results...
// why using the flatMap?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment