Skip to content

Instantly share code, notes, and snippets.

@Busata
Created July 24, 2015 12:48
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 Busata/ccd000ff6426a9cdb4d3 to your computer and use it in GitHub Desktop.
Save Busata/ccd000ff6426a9cdb4d3 to your computer and use it in GitHub Desktop.
List<String> gpsInString = Arrays.asList("GPS_1","GPS_2","GPS_3","GPS_4","GPS_5","GPS_6","GPS_7","GPS_8","GPS_9");
Observable.from(gpsInString).map(new Func1<String, Integer>() {
@Override
public Integer call(String s) {
int coordinate = Character.getNumericValue(s.charAt(4));
System.out.println("Converted "+s+" to "+coordinate);
return coordinate;
}
}).flatMap(new Func1<Integer, Observable<Hotel>>() {
//Example of flatmap, we have a list of coordinates now, but actually we want a list of locations close
@Override
public Observable<Hotel> call(Integer coordinate) {
System.out.println("Fetching hotel for "+ coordinate);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return Observable.just(new Hotel());
}
}).subscribeOn(Schedulers.computation()).toList().toBlocking().last();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment