Skip to content

Instantly share code, notes, and snippets.

@davidmoten
Last active August 29, 2015 14:11
Show Gist options
  • Save davidmoten/de069c45ecbd01e8bd5a to your computer and use it in GitHub Desktop.
Save davidmoten/de069c45ecbd01e8bd5a to your computer and use it in GitHub Desktop.
rxjava example
Observable<Entry<GeoCircleValue<String>> results = tree.search(...);
results
    //get just the name of the city
    .map( entry -> entry.value().value)
    //get the populations asynchronously
    .flatMap(name -> Observable.just(name)
                               .map(n -> new NameAndPop(n, service.populationOf(n))
                               .subscribeOn(Schedulers.io()))
    //observe the results on current thread
    .observeOn(Schedulers.immediate())
    //write the name and the population to the servlet writer
    .subscribe(Subscribers.create(namePop -> out.println(<"p>" + namePop.name() + " " + namePop.pop() + "</p>"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment